
php 正则查找数字转换字符串
问题描述:
在处理 JSON 数据时,遇到如下内容:
<p>{"status":"success","messages":[],"data":{"customrUid":22455399795866744,<span style="background-color: #ff0000">"customerUid":22455399795866744</span></p>
其中红色的数字是需要转换为字符串的。使用以下正则却无法匹配:
立即学习“PHP免费学习笔记(深入)”;
<p>preg_replace('/^"customerUid":(d{1,})./', '"customerUid":"1",', $row);</p>
寻求各位帮助,指出正则表达式的错误之处。
解决方案:
修正后的正则表达式为:
<p>preg_replace('/"customerUid":(d{1,})/', '"customerUid":"1"', $row);</p>
修正之处:
以上就是PHP正则表达式匹配数字并转换为字符串:如何正确使用preg_replace处理JSON数据中的数字?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号