views:

96

answers:

1

In the code below, the privacy_policy.html file has several special characters, including some apostrophes. The function below works fine, however, the contents of the privacy_policy.html file are truncated at the first occurance of the apostrophe.

I'm trying the mysql_escape_string (have also tried "real") to no avail...

$my_privacy_policy = file_get_contents(ABSPATH.'/wp-content/plugins/myplugin/privacy_policy.html');
$my_post3['post_content'] = mysql_escape_string($my_privacy_policy);
A: 

mysql_escape_string is deprecated - I would recommend looking at another function to accomplish what you're trying to do. That alone may fix your problem.

thetaiko
Hi thetaiko, thanks for your feedback on my question. I understand its been deprecated in favor of mysql_real_escape_string(). When I indicated I've also used "real" I meant I used that as well, to no avail. My content still gets truncated at the occurance of the first apostrophe. Any ideas?
Scott B
@ScottB - run `var_dump(mysql_escape_string($my_privacy_policy));` and see what it outputs. That may help you debug it. Another option is to use another function to escape characters. The input is static and controlled by you which means that you don't have to worry quite as much about injection attacks, etc. Try using `addslashes` instead.
thetaiko
@thetaiko, I added the var_dump (on mysql_REAL_escape_string) and the dump was exactly what I wanted (with exception of the \\r\\n characters). However, the content that gets written to the wordpress db (or at least what I'm seeing when I go to edit the newly created page, is still being truncated at the first apostrophe. Any ideas?
Scott B
I was able to get it to work. Had to resave the privacy-policy.html file as UTF-8 (default was ANSI). Also had to just use addslashes (mysql_real_escape_string adds "rn" characters at every paragaph break)Thanks for your help!
Scott B