optikalefx Posted August 9, 2007 Share Posted August 9, 2007 so ive done this once before, but its a lil different this time I want the user in my text box to type in this <link to phil.php displays_as Philosophy<end link> and i want it to translate into <a href='http://www.robbertlaw.com/phil.php'>Philosphy</a> heres the code so far that doenst work. //create link tag $patterns2[0] = "/<link to "; $patterns2[1] = "/<end link>/"; $patterns2[3] = " displays_as "; $replacements2[0] = "<a href='http://www.robbertlaw.com/"; $replacements2[1] = "</a>"; $replacements2[3] = "'>"; $string = preg_replace($patterns2, $replacements2, $string); i thought that it would replace each item and then whats leftover (i.e phil.php) would be in the same spot, just with the switched words/tags. i got it to work with <heading>text</end heading> into <div id="head">text</div> so im not sure why this one wont work. any ideas? btw. Thank you guys so much for helping me with all you did, iv had like 5 topics lately and I really appreciate this forum and you guys who love to help, I will contribute to the helpage when i know more about php, i help a lot on flash actionscript forums, so now i know how it feels to be helped versus helping, and I just wanted to say thanks. Link to comment https://forums.phpfreaks.com/topic/64029-php-pseudo-tags-preg-replace/ Share on other sites More sharing options...
clearstatcache Posted August 9, 2007 Share Posted August 9, 2007 not sure if i get u ryt... $string = "<link to phil.php displays_as Philosophy<end link>"; print "$string\n"; $patterns2[0] = "/<link to /"; $patterns2[1] = "/<end link>/"; $patterns2[3] = "/ displays_as /"; $replacements2[0] = "<a href='http://www.robbertlaw.com/"; $replacements2[1] = "</a>"; $replacements2[3] = "'>"; foreach($patterns2 as $key => $regex) { $string = preg_replace($regex, $replacements2[$key], $string); } print "$string\n"; Link to comment https://forums.phpfreaks.com/topic/64029-php-pseudo-tags-preg-replace/#findComment-319167 Share on other sites More sharing options...
optikalefx Posted August 10, 2007 Author Share Posted August 10, 2007 ok so nice try but i get this error PHP Parse error: syntax error, unexpected T_STRING in /hermes/web04/b1609/pow.4ten/htdocs/php/regex.php on line 12 <? $string = "<link to phil.php displays_as Philosophy<end link>"; print "$string\n"; $patterns2[0] = "/<link to /"; $patterns2[1] = "/<end link>/"; $patterns2[3] = "/ displays_as /"; $replacements2[0] = "<a href='http://www.robbertlaw.com/"; $replacements2[1] = "</a>"; $replacements2[3] = "'>"; foreach($patterns2 as $key => $regex) { $string = preg_replace($regex, $replacements2[$key], $string); } print "$string\n"; ?> heres the code i changed ur [/url] cuz that didnt work either im not sure why this isnt working, all it needs to do is replace these few words with other ones.... Link to comment https://forums.phpfreaks.com/topic/64029-php-pseudo-tags-preg-replace/#findComment-319992 Share on other sites More sharing options...
clearstatcache Posted August 10, 2007 Share Posted August 10, 2007 u sure? wat's d error? i've tested it and it works.....kindly show ur complete code.... Link to comment https://forums.phpfreaks.com/topic/64029-php-pseudo-tags-preg-replace/#findComment-320065 Share on other sites More sharing options...
optikalefx Posted August 10, 2007 Author Share Posted August 10, 2007 ...that is the complete code. and i posted the error. Error: PHP Parse error: syntax error, unexpected T_STRING in /hermes/web04/b1609/pow.4ten/htdocs/php/regex.php on line 12 code: <? $string = "<link to phil.php displays_as Philosophy<end link>"; print "$string\n"; $patterns2[0] = "/<link to /"; $patterns2[1] = "/<end link>/"; $patterns2[3] = "/ displays_as /"; $replacements2[0] = "<a href='http://www.robbertlaw.com/"; $replacements2[1] = "[/url]"; $replacements2[3] = "'>"; foreach($patterns2 as $key => $regex) { $string = preg_replace($regex, $replacements2[$key], $string); } print "$string\n"; ?> this should display a simple hyper link that shows as Philosphy, and links to http://www.robbertlaw.com/phil.php. Link to comment https://forums.phpfreaks.com/topic/64029-php-pseudo-tags-preg-replace/#findComment-320071 Share on other sites More sharing options...
clearstatcache Posted August 10, 2007 Share Posted August 10, 2007 i run ds code.. <? $string = "<link to phil.php displays_as Philosophy<end link>"; print "$string\n"; $patterns2[0] = "/<link to /"; $patterns2[1] = "/<end link>/"; $patterns2[3] = "/ displays_as /"; $replacements2[0] = "<a href='http://www.robbertlaw.com/"; $replacements2[1] = "[/url]"; $replacements2[3] = "'>"; foreach($patterns2 as $key => $regex) { $string = preg_replace($regex, $replacements2[$key], $string); } print "$string\n"; ?> and the output is <link to phil.php displays_as Philosophy<end link> <a href='http://www.robbertlaw.com/phil.php'>Philosophy[/url] i don't know wat's wrong .... Link to comment https://forums.phpfreaks.com/topic/64029-php-pseudo-tags-preg-replace/#findComment-320155 Share on other sites More sharing options...
effigy Posted August 10, 2007 Share Posted August 10, 2007 This works for me: <pre> <?php $string = "<link to phil.php displays_as Philosophy<end link>"; print "$string\n"; $patterns2[0] = "/<link to /"; $patterns2[1] = "/<end link>/"; $patterns2[3] = "/ displays_as /"; $replacements2[0] = "<a href='http://www.robbertlaw.com/"; $replacements2[1] = "</a>"; $replacements2[3] = "'>"; $string = preg_replace($patterns2, $replacements2, $string); print "$string\n"; ?> </pre> Link to comment https://forums.phpfreaks.com/topic/64029-php-pseudo-tags-preg-replace/#findComment-320397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.