当我使用这个本机php函数时出现问题:preg_replace。 有没有人遇到这种情况? 当我运行这个简单的脚本时:
echo preg_replace('/amount_number/i','$100',"this is amount: amount_number");
只输出:
this is amount: 0
尝试了另一个案例:
echo preg_replace('/amount_number/i','$11100',"this is amount: amount_number");
输出:
this is amount: 100
似乎输出字符串已被剪切" $"标志和接下来的2个字母。
答案 0 :(得分:2)
问题是使用$10
从正则表达式获取捕获组(第十)。所以,你必须使用\
来逃避它,就像这样(DEMO):
echo preg_replace('/amount_number/i','\$100',"this is amount: amount_number");
输出:
this is amount: $100