简体   繁体   中英

Advice on display special characters

As intro.. my program read raw data from an input file.. then the program will extract, reformat and do necessary checking/filter and stored in MySQL.

The following is sample data stored in MySQL. FYI, I can't find better option than to stored the values to make it look good on display.

--------------------------------------------------------------------------------------------------------
| ID  | DATA                                                                                           | 
--------------------------------------------------------------------------------------------------------
| 1   | Carol&nbsp;and&nbsp;Anna&nbspare&nbsp;best&nbsp;friends<br>They&nbsp;grew&nbsp;up&nbsp;together|
| 2   | They&nbsp;go&nbsp;to&nbsp;same&nbsp;school<br>They&nbsp;have&nbsp;same&nbsp;hobby.             |
--------------------------------------------------------------------------------------------------------

There some circumstances why i need to store the

&nbsp;  and  < br > 

into MySQL. So, when i want to display it.. i just simply print it and it will appear as expected as follows:

1 Carol and Anna are best friends
They grew up together

2 They go to same school
They have same hobby

All looks good until I have data that contain special character tags such as < > or /. For example.. if i store. Carol says "That's so funny". < Carol laugh >. The words "Carol laugh" inside < > are not display on screen.

My questions are.. do we have a way to display it? or is there any option to store the data? if i use htmlspecialchars() or htmlentities(), it will display together all my and < br >

i need to store those &nbsp and < br > because there are texts that are purposely contain blanks/white spaces.

Any idea guys?

Use html_entity_decode at the time of display the html text.

html_entity_decode — Convert all HTML entities to their applicable characters

Ex:

<?php
$orig = "I'll \"walk\" the <b>dog</b> now";

$b = html_entity_decode($orig);
echo $b; // I'll "walk" the <b>dog</b> now

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM