Aakash Chakravarthy
Aakash Chakravarthy

Reputation: 10691

How to Ignore certain tags and replace texts in PHP

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 .

Upvotes: 2

Views: 1687

Answers (2)

Sev
Sev

Reputation: 15699

Use a HTML DOM parser to get the text within the tags, and then run your str_replace() function on the result.

Upvotes: 2

John
John

Reputation:

http://php.net/manual/en/function.strip-tags.php

This will help u..

Upvotes: 0

Related Questions