doupeng2253 2016-07-26 19:56
浏览 61
已采纳

php preg替换为空格和换行符

i have a text (in file with spaces and tabs)

 <tr>
<th width="219" rowspan="2">dsf</th>
<th width="60" rowspan="2">dsfsdf</th>
<th width="135" colspan="2">dsfdsf</th>

  </tr>

and preg replace search

"!  <tr>
    <th width=\"219\" rowspan=\"2\">dsf</th>
    <th width=\"60\" rowspan=\"2\">dsfsdf</th>
    <th width=\"135\" colspan=\"2\">dsfdsf</th>
  </tr>!is",

it's not my regular expression, but client say that it works before, after some research i'm found that is some problem with spaces or new line /n. If i trying find only one string it's work. I'm tying add /r/n nothing help. Maybe somebody can help me

  • 写回答

1条回答 默认 最新

  • duanpo1498 2016-07-26 19:58
    关注

    Just use \s+ when looking for any whitespace. It's the cheap and easy way out.

    <tr>\s+<th width=\"219\" rowspan=\"2\">dsf</th>\s+<th width=\"60\" rowspan=\"2\">dsfsdf</th>\s+<th width=\"135\" colspan=\"2\">dsfdsf</th>\s+</tr>
    

    See this regex101 link for an example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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