简体   繁体   中英

Replacing ¼ in a php string possible?

我如何在 php 字符串中替换¼我刚刚尝试了以下代码但它不起作用

 $directions=str_replace("¼", "1/4", $directions);

You seem to be suffering as a result of PHP's inability to gracefully handle Unicode.

The character in question can be represented in some versions of extended ASCII, and not in others. It can also be represented in Unicode, by a multi-byte sequence.

What works depends on the input (HTTP input), script (php file), and any other sources (database etc) encoding being consistent.

This character happens to be representable in both ASCII and Unicode, but it seems like you are working on an application that does need to be Unicode.

Once your encoding problem is solved, you can use multi-byte string functions:

echo mb_ereg_replace("¼", "1/4", "¼ of things");

这对我有用

$directions=str_replace(chr(188), "1/4", $directions);

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