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

290 Views Asked by At

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?

1

There are 1 best solutions below

1
On
$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.