简体   繁体   中英

str_replace on ® symbol does not work in PHP

Says it all in the title really. The following code always returns false:

$product = str_replace('®', '', $product);    

I have also tried searching for the html entities for the ® symbol.

Is there a solution for this?

由于文件编码的原因,您必须将符号解码为其实体值( ®

$product = html_entity_decode(str_replace('®', '', htmlentities($product)));

I thing HD-'s answer is right but I'm thinking that this string with special characters are coming from a database and you don't have a quick way to transform the ® sign to its HTML representation &reg ;

The problem you are getting may be originated by the fact that the database connection is using an encoding other than the encoding used by your php script.

If your PHP script is being saved in UTF-8, try the code below:

$product = str_replace('®', '', utf8_encode($product));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM