views:

27

answers:

2

Hello,

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 .

A: 

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

This will help u..

Maybe - he doesn't want to strip nested tags (i.e. anchors within scripts) but if he wants to strip "all tags but <script>" he could use strip_tags($content, '<script>');
Graphain
I dosen't want to strip any tags. When i use str_replace(' ; ', '', $content); the semicolons within the <script> tag get vanished. I don't bother other semicolons. When the semicolon within <script> tag is erased it will give a javascript errorSo except the <script> tag contents others should be replaced.
Aakash Chakravarthy
+2  A: 

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

Sev