Skip to content
Advertisement

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 hyperlink tag into but it fail on regex.. currently it display like this… this DOMDocument loadHTML

How to remove multiple slashes in URI with ‘PREG’ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 10 months ago. Improve this question I am using str_replace() for removing extra slashes from url i dont know how to redirect the url to new url if find multi slashes

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 other

How can i replace all specific strings in a long text which have dynamic number in between?

I am trying to replace strings contains specific string including a dynamic number in between. I tried preg_match_all but it give me NULL value Here is what i am actually looking for with all details: In my long text there are values which contains this [_wc_acof_(some dynamic number)] , i.e: [_wc_acof_6] i want to convert them to $postmeta[‘_wc_acof_14’][0] This can

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: you can benefit from parsing it first: and then making use of the fact that

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+)

Using PHP preg_replace() with a string variable, where the variable needs to represent multiple permutations of itself

Using: I’d like to replace, case-insensitively, the text contained in $My_String, which I can achieve with: If $My_String is alpha beta gamma delta, this will identify: alPhA beTa GammA DeLta aLpHa bEta gAMma delTa etc. So far, so good. But any spaces and hyphens in $My_String must also be regarded as equivalent. So the preg_replace() function also needs to identify

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. EXPLANATION Code snippet:

Advertisement