从PHP中的API中删除单引号(')[重复]

This question already has an answer here:

I JSON decode a page with PHP, but sometimes there's a name like 'M'gladbach' or 'Côte d'Ivoire' and then the SQL sees the first single quote as a stop so it gives me the error after the 'Côte d' Can somebody help me with this problem ? I know you can do 'Côte d''Ivoire' but as I get all the info from a API I can't put double quotes in it. Thanks a lot.

</div>

The proper way to do it is

$item = "Côte d'Ivoire";
$escaped_item = mysqli_escape_string($item);
printf("Protected string : %s
", $escaped_item);

Now it is safe to put e.g. in a database.

use double quotes

"M'gladbach"