从php中的字符串中删除特殊符号

时间:2015-10-20 10:14:42

标签: php mysql

我遇到的问题是根据数据库中的标题获取数据。在标题中它显示一些符号而不是双引号,因为它不起作用。我几乎使用了所有函数,条带标记,str_replacrpregsubstr。但它不起作用。请检查以下字符串,并帮助我如何解决它。

“Generating Six-Figure Online Revenue from Strategic Recruitment Upsells”

我正在使用以下SQL查询。如果我删除了",那就可以了。

 SELECT post_id  as OrderID,`kcx_posts`.post_date as OrderDate,
  MAX(CASE WHEN meta_key='job-title' THEN meta_value END) as JobTitle,
   MAX(CASE WHEN meta_key='_billing_first_name' THEN meta_value END) as   
  FirstName,
  MAX(CASE WHEN meta_key='_billing_last_name' THEN meta_value END) as 
  LastName,
 MAX(CASE WHEN meta_key='_billing_company' THEN meta_value END) as Company,
 MAX(CASE WHEN meta_key='_billing_email' THEN meta_value END) as Email,
 MAX(CASE WHEN meta_key='_order_total' THEN meta_value END) as OrderTotal
FROM `kcx_postmeta` inner join `kcx_woocommerce_order_items` on    
`kcx_postmeta`.post_id= `kcx_woocommerce_order_items`.order_id
inner JOIN  `kcx_posts` ON  `kcx_postmeta`.post_id =  `kcx_posts`.ID  where 
`kcx_woocommerce_order_items`.order_item_name like '%“Generating Six-Figure    
 Online Revenue from Strategic Recruitment Upsells”%' and ( meta_key='job-
title' or meta_key='_billing_first_name' or meta_key='_billing_last_name' or 
meta_key='_billing_company'  or meta_key='_billing_email' or  
 meta_key='_order_total' ) Group By `kcx_posts`.ID desc

我在网站中使用了charset utf-8。有没有办法从数据库中删除它?有很多这样的条目。

1 个答案:

答案 0 :(得分:0)

如果您只想要字母数字字符,这是一个例子:

function clean($string) {
    return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}