Could someone give me an example? I've read the manual
preg_replace
Moderator: General Moderators
preg_replace
I'm confused on the second parameter of preg_replace. All the examples I have seen have numbers and whatnot in em.
Could someone give me an example? I've read the manual
Could someone give me an example? I've read the manual
Simple example that replaces 'fox' with 'new fox'
Code: Select all
<?php
$string = "The quick brown fox jumped over the lazy dog.";
echo preg_replace('/fox/', 'new fox', $string);
//or do the following
//$string = preg_replace('/fox/', 'new fox', $string);
//echo $string;
?>Huh.. simpler than I thought.
So then what would be all this garbled stuff?
I understand regex in terms of matching, but escaping \ and adding numbers is throwing me waaaay off base.
Thanks mark
So then what would be all this garbled stuff?
Code: Select all
function MakeUrl($strUrl)
{
$strUrl = preg_replace("/(http(s)?:\\/\\/[^\\s\\n]*)\\b(\\/)?/i","<a href="\\\\0">\\\\0</a>",$strUrl);
return $strUrl;
}Thanks mark