dtzh131555 2012-10-01 05:46
浏览 26
已采纳

PHP preg_match直到双线中断

I have this data in a mysql field:

First text text text text
 text text text text
 text text text text text text
 text text text text text text

Second text text text text
 text text text text
 text text text text text text
 text text text text text text

I'm trying to preg match from the first word until the double line break. I've tried:

preg_match('/First(.*)

/', $mysqlrow, $m);

This returns no rows. I've also tried the m and s modifiers, which don't return the proper string. I've also tried which doesn't return anything.

How do you do this

  • 写回答

2条回答 默认 最新

  • donmqryh49993 2012-10-01 05:54
    关注

    You need the s modifier and you also need to change your wildcard quantifier to be non-greedy:

    preg_match('/First(.*?)
    
    /s', $mysqlrow, $m);
    

    The s option will cause the . wildcard to match and the non-greedy will cause the * wildcard to not eat up all the it runs across before matching .

    You can also optionally match the just in case you have that in your database:

    preg_match('/First(.*?)?
    ?
    /s', $mysqlrow, $m);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号