php mysql simplexml_load_string() error mysql_escape_string
I save a XML file co开发者_运维知识库ntent in MySQL database with:
$content = mysql_escape_string($content);
$insert = mysql_query("insert into $db_table_xml (url,content) values ('$url','$content')" );
//content type : TEXT in MySQL
simplexml_load_string($content);
it returns an error:
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 361: parser error : AttValue: ' expected in D:\mkw\dev\Web\PHPnow-1.5.6\htdocs\yt2\common.php on line 84
Notice: Trying to get property of non-object in D:\mkw\dev\Web\PHPnow-1.5.6\htdocs\yt2\common.php on line 146
Warning: Invalid argument supplied for foreach() in D:\mkw\dev\Web\PHPnow-1.5.6\htdocs\yt2\common.php on line 146
This error means it is not valid xml, inspect the xml file to see if there is anything wrong with it.
Look for line 361 in it, there is probably special character or similar error
Edit.
Obviously when you escape the xml, you introduced invalid characters in your xml,
use.
$content_escape = mysql_escape_string($content);
$insert = mysql_query("insert into $db_table_xml (url,content) values ('$url','$content_escape')" ); //content type : TEXT in MySQL
now your $contents is not affected
Looks to me like your variable $content contains single quotes that are affecting the termination of the string. This is what your can do if this is the case:
$content= addslashes($content);
Then you write this into your record.
精彩评论