preg-replace

Regex / DOMDocument - match and replace text not in a link

I need to find and replace text in a case insensitive way, unless it is within an anchor tag - for example: <p>Match this text and replace it</p> <p>Don't <a href="/">match this text</a></p> Searching for 'match this text' would only replace the first instance. [Edit] As per Gordon's comment, it may be preferred to use DOMDocument in...

Manipulating preg_replaces's 'replace' value

I'm trying to alter the match value from preg_replace with an uppcase copy but cant seem to figure it out... I've tried: preg_replace("#\[name=((?:keywords)|(?:description))\]#is", "[name=" . strtoupper($1) . "]" ,$str ) and preg_replace("#\[name=((?:keywords)|(?:description))\]#is", "[name={strtoupper($1)}]" ,$str ) but none work...

How to obscure the numbers in the textarea field.

Hi, I have using cakephp and I want to obscure all numbers which is more than six digits. something like this $string = "My id number is 77765444 in Sales dept."; becomes $string = "My id number is XXXXXXXX in Sales dept." I appreciate any help. Thanks. ...

Calling a php function from a preg_replace causes the function to load at the top of the page

We have some bbcode and I'm trying to setup the ability for a certain code to call a function that loads some images from our photo gallery. So if someone puts in an album number, it pulls 5 of the most recent photos out. When we call this function regularly (on another page, just as a regular php statement), it works as expected. But wh...