Two quick ereg_replace() questions...
Posted: Mon Nov 24, 2003 11:22 am
I'm finally starting to get my head around the ereg type stuff (as always it's easy once you know how to do it). I'm stuck one thing though at the moment.
How would I get an ereg search to look for either THIS or THAT?
For example here I'm trying to get the replacement to work if an optional blank space but not a quote exists before the http://
$text should end up looking like this..
xxxx<a href="http://www.somewhere.com">http://www.somewhere.com</a> <a href="http://www.somewhere.co.uk">http://www.somewhere.co.uk</a> <a href="http://www.somewhere.net">link</a>
Cheers.
How would I get an ereg search to look for either THIS or THAT?
For example here I'm trying to get the replacement to work if an optional blank space but not a quote exists before the http://
Code: Select all
<?php
$text = "xxxxhttp://www.somewhere.com http://www.somewhere.co.uk <a href="http://www.somewhere.net">link</a>";
$searchFor = "([\\s]?[^"])http://([^\\s]+)";
$replaceWith = "\\1<a href="http://\\2">\\2</a>";
$text = eregi_replace($searchFor, $replaceWith, $text);
?>xxxx<a href="http://www.somewhere.com">http://www.somewhere.com</a> <a href="http://www.somewhere.co.uk">http://www.somewhere.co.uk</a> <a href="http://www.somewhere.net">link</a>
Cheers.