I have a MySQL database that has lots of text in.
some of the characters used are things like &, ®
How can I make sure that when a php script calls the data it converts all the characters in to the correct html e.g.
& = &
® = ®
I have a MySQL database that has lots of text in.
some of the characters used are things like &, ®
How can I make sure that when a php script calls the data it converts all the characters in to the correct html e.g.
& = &
® = ®
http://us3.php.net/htmlentitiesPHP Code:htmlentities($tring);
Had tried that but it didn't work. Just realized why not though.
here is an example of the text in my database:
I want to include the <br>'s as line breaks but change the charachters into html.some text here & some more text here <br>
some text here & some more text here ® <br><br>
some text here & some more text here ®
I want it to output html like this
Is this possible?some text here & some more text here <br>
some text here & some more text here ® <br><br>
some text here & some more text here ®
yeah, just include that & in your database. If your database is reading the <br/>'s back as html line breaks, what makes you think it won't read & as the & symbol?![]()
htmlspecialchars($tring);
is the other method to which parse character codes.
some characters are harmful to the database, some characters are harmful to the web browser. its better to just do the distinction when the time comes...yeah, just include that & in your database. If your database is reading the <br/>'s back as html line breaks, what makes you think it won't read & as the & symbol?
eg (%) is a quantifier in a SQL Database, however (%) is perfectly acceptable in a web browser. translation should always be done where appropriate if possible.
this is very fishy as a possible misuse of the break line tag.some text here & some more text here <br>
some text here & some more text here ® <br><br>
some text here & some more text here ®
perhaps use<span>text</span>and in your stylesheet putspan { display:block }
It's better to use
Code:<p>some text</p><p>some text</p>
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
Thanks for all you help!
I have now sorted the problem.
The problem was that I already have hundreds of entries in my database similar to this, and would take hours to edit them all:
my solution was thesome text here & some more text here <br> something else could go here <br>
some text here & some more text here® <br><br>
some text® here & some more text herestr_replace()function e.g.
This then would output this HTML:PHP Code:$text_from_database = "this text was generated by a mysql query <br> & contains some symbols®";
$replace_this = array("®", "&");
$replace_with = array("®", "&");
print str_replace($replace_this, $replace_with, $text_from_database);
this text was generated by a mysql query <br> & contains some symbols®
Which would then display like this in the browser:
this text was generated by a mysql query
& contains some symbols®
Bookmarks