I have string:
<p justify;"="">Verslo centrai Lietuvos nekilnojamojo turto plėtros asociacijos konkurse ...</p>
and want want remove tag
<p justify;"=""></p>
my code:
$content = strip_tags($text, '<p>');
but i get empty string: string(0) ""
, what I do wrong ?
Try to put it like that
$content = strip_tags($text);
Or you can do it with regular expression like that:
$content = preg_replace('/<[^>]*>/', '', $text);
By this $content = strip_tags($text, '<p>');
you are allowing the <p>
tag in the string.
For more info see the link http://php.net/manual/en/function.strip-tags.php
Since your HTML is not properly formatted you could choose a 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 ... "
Codepad Example
On strip_tags() docs it says: Because strip_tags() does not actually validate the HTML, partial or broken tags can result in the removal of more text/data than expected.
Also second parameter is for $allowable_tags
.
Since the HTML is poorly formated you probably need to either write your own regexp to remove tags or clean up the HTML before trying to remove tags.
You could try this to remove everything that "looks like" a tag:
$str = preg_replace("/<.*?>/", " ", $str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With