douxueke5653 2011-06-01 18:33
浏览 53

preg_match未知修饰符'。' 在wordpress [重复]

This question already has an answer here:

I'm trying to do something simple...I thought?

Have the following...

$current = '/zeta/2010/03/';

preg_match('/zeta/.{4}/(.{2})/$',$current,$monthnum); 

Simply am trying to make $monthnum = 03

Keep either getting an unknown modifier error or, when I add the delimiters '#/zeta/.{4}/(.{2})/$# it returns with simply #Array...

Can anyone help?

</div>
  • 写回答

2条回答 默认 最新

  • dongtang1918 2011-06-01 18:39
    关注

    PCREs have to be enclosed in delimiters.

    You have to either escape the inner \ or use another delimiter:

    ~/zeta/.{4}/(.{2})/$~'
    

    Otherwise, PHP thinks the expression is /zeta/ only and . is not a valid modifier.

    preg_match does not return an array. You can inspect the contents of $monthnum with var_dump and access the information you want.

    You could have solved your problem by simply reading the documentation:

    If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.

    and

    preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测