Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Generating Valid w3c html from data in DB using PHP
Old 08-22-2011, 08:43 PM Generating Valid w3c html from data in DB using PHP
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
Hi
I have a serious problem with a load of data that is in my db.

In a lot of the Db fields there is HTML such as < and > together with &

I am extracting this data fine however, when it renders it is NOT valid HTML and is falling over on the w3c check with errors and warnings like below:

You tried to include the "<" character in your page: you should escape it as "&lt;"
You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.

So my question is how can i extract these characters and render in valid way so as to pass validation check?

Really hope someone can help with this as have been up half the night trying to sort with no progress.

Cheers
Steve
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 08-23-2011, 05:29 AM Re: Generating Valid w3c html from data in DB using PHP
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Either use the str_replace() function in php after retreiving the data, or change the data itself using MySQLs' REPLACE() function.

EDIT: And in the future, make this replacement before the data is stored in your database
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 08-23-2011 at 05:31 AM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-23-2011, 07:50 AM Re: Generating Valid w3c html from data in DB using PHP
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
No. You have to store the full text (with HTML) and only show it how you like it (using htmlentities OR not). The reason your code is not w3c compliant is because of the content, make it OK before storing it.
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 08-24-2011, 01:51 PM Re: Generating Valid w3c html from data in DB using PHP
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Quote:
Originally Posted by vectorialpx View Post
No. You have to store the full text (with HTML) and only show it how you like it (using htmlentities OR not). The reason your code is not w3c compliant is because of the content, make it OK before storing it.
NO!

As a general principle you do not modify data before storing just to suit a later use or presentation of the data.

To give a quick example, imagine the stored data was student's responses to marked exercises. Manipulating before storing woukld be very bad.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 08-25-2011, 02:18 AM Re: Generating Valid w3c html from data in DB using PHP
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
Quote:
Originally Posted by PaulW View Post
As a general principle you do not modify data before storing just to suit a later use or presentation of the data
That's what I said...
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 08-25-2011, 06:56 AM Re: Generating Valid w3c html from data in DB using PHP
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Quote:
Originally Posted by vectorialpx View Post
make it OK before storing it.
So er?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 08-27-2011, 06:00 AM Re: Generating Valid w3c html from data in DB using PHP
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
Quote:
make it OK before storing it
This is not my entire post. Look upper, I bet you can read more than those last 6 words.
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Reply     « Reply to Generating Valid w3c html from data in DB using PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37702 seconds with 12 queries