[英]Extract digit from unicode string - PHP RegExpression
I am Parsing a web page for getting the web page prize. 我正在解析一个网页,以获取网页奖品。 the prize include a Rupee symbol (₹). 奖品包括卢比符号(₹)。
So i used preg_replace to extract digits. 所以我用preg_replace提取数字。
For example: 例如:
$str='₹ 1,195 ';
echo preg_replace("/[^0-9]/", '', $str);
Output is : 输出为:
2091195
I tried same code to execute on http://writecodeonline.com/php/ . 我尝试在http://writecodeonline.com/php/上执行相同的代码。
There im getting correct output 1195
. 我得到正确的输出1195
。
I'm not getting what is the problem. 我没有什么问题。
Thanks in Advance 提前致谢
If the unicode string is UTF-8, you can use the u (PCRE_UTF8) modifier Docs to tell preg_replace
that it should use UTF-8 mode. 如果Unicode字符串为UTF-8,则可以使用u (PCRE_UTF8)修饰符Docs告诉preg_replace
它应使用UTF-8模式。 If not, re-encode it to UTF-8 first and then use the modifier. 如果不是,请先将其重新编码为UTF-8,然后使用修饰符。
$subject = '₹ 1,195 ';
$pattern = "/[^0-9]/u";
$result = preg_replace($pattern, '', $subject);
echo $result;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.