gpt4 book ai didi

php - 未知修饰符 'g' PHP 正则表达式错误

转载 作者:可可西里 更新时间:2023-11-01 00:10:45 25 4
gpt4 key购买 nike

我的模式是:/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g和数据:http://gskinner.com/RegExr/?2ujor

和php代码:

$regexp = ' /(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g';
if(preg_match("$regexp", $input, $matches, PREG_SET_ORDER)) {
for($i=0;$i<14;$i++){
echo '--->'.$i.'-->'.$matches[0][$i];

}}

result: Warning: preg_match() [function.preg-match]: Unknown modifier 'g'

$regexp = ' /(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g';
if(preg_match_all("$regexp", $input, $matches, PREG_SET_ORDER)) {
for($i=0;$i<14;$i++){
echo '--->'.$i.'-->'.$matches[0][$i];

}}

result: Warning: preg_match_all() [function.preg-match-all]: Unknown modifier 'g'

此解决方案无效! :| "Unknown modifier 'g' in..." when using preg_match in PHP?

我该怎么办?

最佳答案

切换到 preg_match_all 是正确的,现在您需要做的就是从正则表达式中删除“g”:

$regexp = '/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/';

关于php - 未知修饰符 'g' PHP 正则表达式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7292582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com