optikalefx Posted August 11, 2007 Share Posted August 11, 2007 this is my 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"; ?> the purpose is to replace <link to phil.php display_as Philosophy<end link> with <a href='http://www.robbertlaw.com/phil.php'>Philosphy</a> I keep getting this error PHP Parse error: syntax error, unexpected T_STRING in /hermes/web04/b1609/pow.4ten/htdocs/php/regex.php on line 12 Quote Link to comment Share on other sites More sharing options...
teng84 Posted August 11, 2007 Share Posted August 11, 2007 its not giving me an error although the ouput seems to be an error and why do you have to loop this Quote Link to comment Share on other sites More sharing options...
optikalefx Posted August 11, 2007 Author Share Posted August 11, 2007 to tell you the truth, thats not the code i was using, that is one someone helped me make because mind gave me an error. my code was this <? $string = "<link to phil.php display_as Philosophy<end link>"; //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); ?> and it still gives me an error... Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 11, 2007 Share Posted August 11, 2007 <link to phil.php display_as Philosophy<end link> with <a href='http://www.robbertlaw.com/phil.php'>Philosphy</a> i think this is what you want <?php $Find = "<link to phil.php display_as Philosophy<end link>"; $replace= preg_replace('/<link to ([\S]*) display_as (.*)(?:<end link>)/i', '<a href=\'http://www.robbertlaw.com/$1\'>$2</a>', $Find); echo replace; ?> returns <a href='http://www.robbertlaw.com/phil.php'>Philosophy</a> Quote Link to comment Share on other sites More sharing options...
optikalefx Posted August 12, 2007 Author Share Posted August 12, 2007 awsem except its blank and gives me this error PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /hermes/web04/b1609/pow.4ten/htdocs/php/regex.php on line 7 Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 12, 2007 Share Posted August 12, 2007 can you post the first 10 lines of your code please (from the regex.php file) Quote Link to comment Share on other sites More sharing options...
optikalefx Posted August 13, 2007 Author Share Posted August 13, 2007 heres the entire code <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> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 13, 2007 Share Posted August 13, 2007 your code should be this <?php $Find = "<link to phil.php display_as Philosophy<end link>"; $replace= preg_replace('/<link to ([\S]*) display_as (.*)(?:<end link>)/i', '<a href=\'http://www.robbertlaw.com/$1\'>$2</a>', $Find); echo replace; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.