Verslo centrai Lietuvos nekilnojamojo turto plėtros asociacijos konkurse ...

PHP removing html tags from string

I have a line:

<p justify;"="">Verslo centrai Lietuvos nekilnojamojo turto plėtros asociacijos konkurse ...</p> 

and want to remove the tag

 <p justify;"=""></p> 

my code is:

 $content = strip_tags($text, '<p>'); 

but I get an empty string: string(0) "" , what am I doing wrong?

+7
source share
6 answers

Try to say so

 $content = strip_tags($text); 

Or you can do it with regex:

 $content = preg_replace('/<[^>]*>/', '', $text); 

Under this $content = strip_tags($text, '<p>'); you allow the <p> in the string.

For more details see the link http://php.net/manual/en/function.strip-tags.php

+15
source

Since HTML is poorly formed, you probably need to either write your own regular expression to remove tags or clear HTML before trying to remove tags.

You can try this to remove everything that looks like a tag:

 $str = preg_replace("/<.*?>/", " ", $str); 
+4
source

This will remove every thing - tags, ascii, line breaks, but plain text:

 strip_tags(preg_replace('/<[^>]*>/','',str_replace(array("&nbsp;","\n","\r"),"",html_entity_decode($YOUR_STRING,ENT_QUOTES,'UTF-8')))); 
+3
source

Since your HTML is not formatted correctly, you can choose the preg_replace() approach:

 $text = '<p justify;"="">Verslo centrai Lietuvos nekilnojamojo turto plėtros asociacijos konkurse ... </p>'; $content = preg_replace('/<[^>]*>/', '', $text); var_dump($content); // string(108) "Verslo centrai Lietuvos nekilnojamojo turto plėtros asociacijos konkurse ... " 

Code Example

Strip_tags () docs says: Since strip_tags () does not actually check HTML, partial or broken tags can be obtained when deleting more text / data than expected.

Also the second parameter for $allowable_tags .

+2
source

This will replace all html tags, https://regex101.com/r/jM9oS4/4

 preg_replace('/<(|\/)(?!\?).*?(|\/)>/',$replacement,$string); 
0
source

It may help php-strip-tags

ok if prep_replace is not working, try using jquery to remove html tags.
see this post javascript-how-to-strip-html-tags

-3
source

All Articles