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?
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
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); This will remove every thing - tags, ascii, line breaks, but plain text:
strip_tags(preg_replace('/<[^>]*>/','',str_replace(array(" ","\n","\r"),"",html_entity_decode($YOUR_STRING,ENT_QUOTES,'UTF-8')))); 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 ... " 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 .
This will replace all html tags, https://regex101.com/r/jM9oS4/4
preg_replace('/<(|\/)(?!\?).*?(|\/)>/',$replacement,$string); 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