John Davidson

cant remove html entities in php

0 comments
Message:


Good morning everyone,


I try to "clean" a string with html entities in php but its not working :-/.


Here is my simple code example:


$body = "Mal ein neuer <b>Test</b><br>";
$body = html_entity_decode($body);
$body = strip_tags($body);

var_dump($body);

The Output is:


string(47) "Mal ein neuer <b>Test</b><br>" 

Someone have an idea that my result ist just "Mal ein neuer Test"?


best regards,
Niklas



My Answer:
remove HTML entities in PHP using the `htmlspecialchars_decode()` function. Here's an example:

php
$html = "Good morning everyone,<br>I try to";
$decoded_html = htmlspecialchars_decode($html);
echo $decoded_html;


This will output:


Good morning everyone,
I try to


This function will decode all HTML entities in the given string.

Rate this post

4 of 5 based on 6015 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us