Hi please any one give me a soloution for this. I want to remove the entire div and span from this html except 4 in <span>
. Any one please
<div class=\"fivestar-widget-static fivestar-widget-static-vote fivestar-widget-static-5 clear-block\">
<div class=\"star star-1 star-odd star-first\">
<span class=\"on\">4</span>
</div>
<div class=\"star star-2 star-even\">
<span class=\"on\"></span>
</div>
<div class=\"star star-3 star-odd\">
<span class=\"on\"></span>
</div>
<div class=\"star star-4 star-even\">
<span class=\"on\"></span>
</div>
<div class=\"star star-5 star-odd star-last\">
<span class=\"off\"></span>
</div>
</div>
PHP provides an inbuilt function to remove the HTML tags from the data. The strip_tags() function is an inbuilt function in PHP that removes the strings form HTML, XML and PHP tags. It accepts two parameters. This function returns a string with all NULL bytes, HTML, and PHP tags stripped from a given $str.
To strip out all the HTML tags from a string there are lots of procedures in JavaScript. In order to strip out tags we can use replace() function and can also use . textContent property, . innerText property from HTML DOM.
To strip HTML tags but leave their text content, you can just use strip_tags
:
$string = "<div>Hello</div> <span>Hi</span> Other text";
$string = strip_tags($string);
// You'll probably also want to trim the results
// to remove extraneous whitespace
$string = trim($string);
Which will result in "Hello Hi Other text"
PHP Manual: http://php.net/manual/en/function.strip-tags.php
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