How to Ignore certain tags and replace texts in PHP
-
26-09-2019 - |
Question
I have a variable like
$content = "Lorem Ipsum is simply <b>dummy text of the printing</b> and typesetting industry.
Lorem Ipsum has been the industry's <i>standard dummy text</i> ever since the 1500s
<string>javascriptFunc();</script>" ;
when i use str_replace('a', '', $content);
all the 'a's get removed. But the 'a's within the <script>
tag should not be removed.
or is there any way to replace text other than this method
Please help .
Solution
Use a HTML DOM parser to get the text within the tags, and then run your str_replace() function on the result.
OTHER TIPS
http://php.net/manual/en/function.strip-tags.php
This will help u..
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow