RSS to Database - How to Insert String with Any Character?
I'm scraping a feed and adding the values to a database.
One of the values is description. Description is freestyle so there can be any character.
How do I insert the values into the database to display it on a webpage later. I want to keep the description and title text as is.
...
$title = $item['title'];
$href = $item['link'];
$desc = $item['description'];
$query = "INSERT INTO FEED_CONTENT (title, link, desc) VALUES ('".mysql_real_escape_string($title)."','开发者_JS百科".$href."',
'".mysql_real_escape_string($desc)."')";
...
Thanks
Using mysql_real_escape_string with the magic quotes enabled will escape your data twice.
Note: If magic_quotes_gpc is enabled, first apply stripslashes() to the data. Using this function [mysql_real_escape_string] on data which has already been escaped will escape the data twice.
While outputting those content you can use stripslashes function.
echo stripslashes($data['description']);
EDIT
desc
is mysql reserved word and you must enclose desc
in backticks ``
$query = "INSERT INTO FEED_CONTENT (title, link, `desc`)
VALUES (
'".mysql_real_escape_string($title)."',
'".$href."',
'".mysql_real_escape_string($desc)."'
)";
精彩评论