Skip to content

Tag: preg-replace

php DOMDocument preg_replace fail detect

Basically, I want to replace content with hyperlink when detected matching keyword tag. the replace need to be outside of caption/image/figure/figcaption/iframe/a of existing content, because putting hyperlink inside these will causing format breaking. my php Now I facing 2 issue want to exclude replace hyper…

PHP Regex: Remove words not equal exactly 3 characters

An excellent “very close” answer at Remove words less than 3 chars with DEMO where Regex removes all words less than 3 chars. But how to reset this demo vise versa ? to remove all words NOT EXACTLY EQUAL 3 chars ? We can catch word where exactly 3 chars by but how to tell regex – remove all …

Remove characters from beginning and end string

I want to ouput only MYID from URL. What I did so far: output: https://whatever.expamle.com/display/MYID ouput: MYID?out=1234567890?Browser=0?OS=1 How can I combine this? Thanks. Answer When the string is always a Uniform Resource Locator (URL), like you present it in your question, given the following string…

PHP add html tag to first word

Trying to add HTML tags around the first word in each new line in WooCommerce short description and validate that the file exist. If it exist it will output a link. I tried this: This is as close I could get, the limitation is that you need to add all words that needs to be changed (will be total 200+)

Regex to find and expression and insert into the middle

I’ll be brief as I can. I’m trying to use preg_replace’s regex to find a digit, but I want to non destructively edit the string. an example: (albeit this is an approximation due to data protection) Any help would be gratefully received Answer Use Replace with <hr/>$0. See regex proof. …