jamesxg1 Posted January 7, 2011 Share Posted January 7, 2011 Hiya peeps! I'm not sure this is possible but here is a example code of what I'm trying to do, I hope it shows my intentions; if(preg_match_all("/\%([A-Z]*)%/", $file, $match)) { while($results = mysql_fetch_array($runSearch)); foreach($match[1] as $MK => $MV) { $TR .= str_replace('%' . $MV . '%', $results[$MV], $match[1]); } return $TR; } else { return $this->lang->displayContent('39'); } I would test it and make life a whole lot easier; but I have built the whole site freehand and I know 100% the rest of the code will work, this on the other hand has stumped me! I also have now sample data in the mysql database and I do not have the tables correctly setup yet. So I pretty much on a short string with this one! Any help would be very much appreciated! Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/223667-im-not-sure-this-is-possible-but-if-it-is-how-would-i-do-it/ Share on other sites More sharing options...
jamesxg1 Posted January 7, 2011 Author Share Posted January 7, 2011 What I'm basically trying to do is this; Input into the script; <a href="blah.php?id=%id%">%name%</a> and then have the %CONTENT% replaced with results from an array fetched from the mysql DB. EG; Input; <a href="blah.php?id=%id%">%name%</a> Output; <a href="blah.php?id=1">John Doe 1</a> <a href="blah.php?id=2">John Doe 2</a> <a href="blah.php?id=3">John Doe 3</a> And so on, is this possible? and am I on the right tracks? lol. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/223667-im-not-sure-this-is-possible-but-if-it-is-how-would-i-do-it/#findComment-1156167 Share on other sites More sharing options...
jamesxg1 Posted January 7, 2011 Author Share Posted January 7, 2011 I've got this so far, but due to being unable to test it I'm not sure if it will work. Would someone with a good all seeing eye take a look and tell me if this will work please lol. if(strpos($replacements, '%') == true) { while($results= mysql_fetch_assoc($runSearch)) { if(preg_match("/\%([A-Z]*)\%/", $replacements, $containers)) { foreach($containers as $CK => $CV) { $TR .= str_replace('%' . $CV . '%', $results[$CV], $replacements); } } } return $TR; } else { return $this->lang->displayContent('39'); } Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/223667-im-not-sure-this-is-possible-but-if-it-is-how-would-i-do-it/#findComment-1156186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.