Zen Cart Logo
Forums / General Questions / creating dynamic links on product description

creating dynamic links on product description

Locked

Views: 1,446

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
10 Nov 2006, 11:52 AM
#1
sn0ut avatar

sn0ut

New Zenner

Join Date:
Oct 2005
Location:
UK - London
Posts:
56
Plugin Contributions:
3

creating dynamic links on product description

Hey all....

My client has just asked me for a feature which I think should be possible but I need a little help getting started.

The store sells bodybuilding supplements and health drinks etc.... He has a load of fact sheets on protein, bodyfat etc.....

Is there anyway I can dynamically replace all instances of the word protein with a link to the relavent doc?

Or does a hack like this exist already?

Ta!

10 Nov 2006, 7:51 PM
#2
seethrou avatar

seethrou

Totally Zenned

Join Date:
May 2004
Location:
Hong Kong
Posts:
1,156
Plugin Contributions:
0

Re: creating dynamic links on product description

There is a contribution in the download area, may be a starting point.
Description_Diagram_ImagePopup

A New Starter again

11 Nov 2006, 12:38 PM
#3
sn0ut avatar

sn0ut

New Zenner

Join Date:
Oct 2005
Location:
UK - London
Posts:
56
Plugin Contributions:
3

Re: creating dynamic links on product description

ok so i got this far:

<?


$protein = "yummy protein bars <br /><br />"; 
 echo str_replace_once("protein", array("<a href='http://www.google.com'>protein</a>"), $protein);



$creatine = "creatine is the blah blah blah blah blah"; 
echo str_replace_once("creatine", array("<a href='http://www.google.com'>creatine</a>"), $creatine);




function str_replace_once($search, $replace, $subject, &$offset = 0) {

       if (is_array($replace)) {
           foreach ($replace as $value) $subject = str_replace_once($search, $value, $subject, $offset);
       } else {
           $pos = strpos($subject, $search, $offset);
           if ($pos !== false) {
               $offset = $pos+strlen($search);
               $subject = substr($subject, 0, $pos) . $replace . substr($subject, $offset);
           }
       }

  
   return $subject;
}


?>

Any ideas how I should put it in Zen?