preg_replacePREG_BAD_UTF8_ERROR [英] preg_replace PREG_BAD_UTF8_ERROR

查看:120
本文介绍了preg_replacePREG_BAD_UTF8_ERROR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个恼人的问题与 preg_replace 和字符集。我在连续做一对夫妇 preg_replace ,但不幸的是第一次任何特殊字符,如äöüß插入preg_replace我在后续调用中得到 PREG_BAD_UTF8_ERROR

i have an annoying problem with preg_replace and charsets. I'm doing a couple preg_replace in a row but unfortunate the first time any special character like äöüß is inserted by preg_replace i'm getting PREG_BAD_UTF8_ERROR on subsequent calls.

除了插入的特殊字符显示得很好,断开任何后续的 preg_replace 调用。只有preg_ utf-8吗?

Beside that the special characters inserted are displayed just fine, they just break any subsequent preg_replace call. Is preg_ utf-8 only?

正在处理的文本是来自MySQL数据库,是在php文件中制作的MySQL中的值。 mb_detect_encoding()表示 ASCII 为文本,直到第一次替换为特殊字符,然后检测 UTF-8 ,所以它改变,这可能是问题。

The text preg_replace is working on is coming from MySQL Database, also the replacement is crafted in the php file with values from MySQL. mb_detect_encoding() says ASCII for the text until the first replacement with special characters, it then detects UTF-8, so it changes and this might be the problem.

为了您的信息,我使用iso-8859-1编码(PHP,MySQL,元字符集)。

For your information i'm working with iso-8859-1 encoding (PHP, MySQL, meta-charset). Furthermore i have a workaround with htmlentities on the replacement string that is working for now.

有关如何解决这个问题的任何想法吗?

Any ideas on how to solve it?

推荐答案

您正在寻找的可能是 mb_ereg_replace 。它处理多字节编码,应该与不同的编译器执行。请务必同时使用 mb_regex_encoding

What you are looking for is probably mb_ereg_replace. It handles multibyte encodings and should perform fine with differrent ones. Be sure to use mb_regex_encoding along with it.

这篇关于preg_replacePREG_BAD_UTF8_ERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆