0

I want to replace text in Chinese + English inside the quotes:

sample source text:

emMsg('您的php版本过低,请选用支持PHP5的环境安装english word。');

or

(程序不会自动创建数据库,请提前创建一个空数据库或使用已有数据库)

preg_replace("/(?:[(]([\p{Han}]+)[)] )?/ux", '-', $val);

but the result is not obtained, what am I doing wrong?

Toni Toni Chopper
  • 1,833
  • 2
  • 20
  • 29
Den68
  • 27
  • 6
  • 1
    You showed us sample source text. Could you provide us a result example too? What do you expect to get? – Jurik Dec 06 '13 at 16:52
  • There are a lot of prior questions/answers on this subject. http://stackoverflow.com/questions/8989133/remove-all-except-the-chinese-characters-with-regex – Andrew - OpenGeoCode Dec 06 '13 at 17:44
  • to Jurik: Expect to get cut all the text inside the brackets, and replace it by a '-' – Den68 Dec 06 '13 at 18:11

1 Answers1

0
$str = "emMsg('您的php版本过低,请选用支持PHP5的环境安装english word。');";
$res = preg_replace( "~emMsg\(('*)(.+?)('*)\);~", 'emMsg(\\1-\\3);', $str );
print_r( $res );

IS this what you mean?

$str = "emMsg('您的php版本过低,请选用支持PHP5的环境安装english word。');";
$str = preg_replace( "~\p{Han}+~u", '', $str );
$res = preg_replace( "~emMsg\(('*)(.+?)('*)\);~", 'emMsg(\\1\\2\\3);', $str );
print_r( $res );

I don't think you can match all the Han mixed with Latin in any format.

Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48
  • Thank you for your example, but it does not account for the presence of the Chinese language in parentheses. Should be removed only in klnstruktsii Chinese alphabet. In the original data in brackets may find ourselves and only the English text. – Den68 Dec 08 '13 at 17:21