Removing smart quotes from sql.
Posted: Sun Oct 09, 2011 5:10 am
I have a database which has products in, the names of the products are displayed as normal quotations in the database ' ... however on the website they get reverted to smart quotations.
I'm using a function that comes with one of the wordpress plugins to call price based on name of product.
The problem is the MySQL cannot read the smart quotes.
I found a bit of code, which is supposed to remove these smart quotes.
Which I then use as follows:
But it doesnt seem to work.
Any ideas what I'm doing wrong?
Thanks,
Aravona
I'm using a function that comes with one of the wordpress plugins to call price based on name of product.
The problem is the MySQL cannot read the smart quotes.
I found a bit of code, which is supposed to remove these smart quotes.
Code: Select all
function convert_smart_quotes($string)
{
$search = array(chr(145),
chr(146),
chr(147),
chr(148),
chr(151));
$replace = array("'",
"'",
'"',
'"',
'-');
return str_replace($search, $replace, $string);
} Code: Select all
$query = 'SELECT wp_wpsc_product_list.price FROM `wp_wpsc_product_list` WHERE wp_wpsc_product_list.name = "' . wpsc_the_product_title() . '"';
$query2 = convert_smart_quotes($query);Any ideas what I'm doing wrong?
Thanks,
Aravona