John Davidson

How to properly bold the decoded data in PHP

0 comments
Message:


I am posting data to database which requires that I encode it. To this effect I used htmlentities() and to decode it am using html_entity_decode()


Here is my issue: My problem is that the decoded result is does not bold the "Helloworld" rather it shows back the Helloworld surrounded by the HTML bold tags.


$str = "<b>Hello world</b>";

echo $en = htmlentities(htmlentities($str));

echo "<br>decode<br>";

echo $result = html_entity_decode($en);


My Answer:
To properly bold the decoded data in PHP, you can use the following code:

php
$str = "<b>Hello world</b>";

echo $en = htmlentities(htmlentities($str));

echo "
decode
";

echo $result = html_entity_decode($en, ENT_QUOTES);


By adding the `ENT_QUOTES` parameter to the `html_entity_decode` function, it will decode both double and single quotes, which will properly display the bolded text "Hello world" without the HTML bold tags.

Rate this post

4 of 5 based on 3076 votes

Comments




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