douzhantanju1849 2015-11-20 23:57
浏览 38
已采纳

php删除2个标签之间的空白[重复]

This question already has an answer here:

I am trying to remove signature of an email before inserting the message into a database. The signature is enclosed in a special tag, xxx to help strip out.

The following only works if the signature is condensed without whitespace spread over various lines.

    $msgeBody = preg_replace('#(<signature>).*?(</signature>)#', '$1$2', $msgeBody);

I have tried possibilities found online to remove whitespace first between these tags, before applying the line above. But no success. How to do? Here is the sample text spread over lines:-

    <signature><p><span style="font-weight: bold;">Gerald Sugan</span><br>
    Travel Consultant<br>
    <span style="font-size: 18px; font-family: 'Courier New'; font-weight: bold;">Sugan Enterprises Inc</span></p>
    </signature>

The solution of php preg_replace regex that matches multiple lines is not a duplicate. I could not see how to apply those solutions here. The solution found below is different I think.

</div>
  • 写回答

4条回答 默认 最新

  • duanhe4267 2015-11-21 00:30
    关注

    Here is a simple regex that match your signature : <signature>[\S\s]*<\/signature>

    \S : Matches anything other than a space, tab or newline.
    \s : Matches any space, tab or newline character.
    * : Matches zero or more consecutive characters.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源