duangu1868 2010-02-15 01:33
浏览 18
已采纳

删除位于<b> </ b>中间的文本

I Have Text in the middle of <b></b> Eg:

La  <b>la</b>: the  1  <br></br>Aventuroj  <b>aventuro</b>: adventure  2  <br></br>de  <b>de</b>: by, from, of, since  3  <br></br>Mirlando  <b>miri</b>: marvel, marvel at, wonder<br/><b>lando</b>: country, land  4  <br></br>by  <b>ba</b>: bah, nuts, pooh  5  <br></br>for  <b>for</b>: away  6  <br></br>

I would like maybe a regex that would strip the text and the <b></b> from the string

Thanks

★✩

  • 写回答

2条回答 默认 最新

  • dongyi4170 2010-02-15 01:36
    关注

    The simplest way is to use preg_replace():

    $output = preg_replace('!<b>.*?</b>!s', '', $input);
    

    The s on the end is a flag. See Pattern Modifiers for a list of flags.

    s (PCRE_DOTALL)

    If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.

    Generally speaking however regexes are a poor tool for querying and manipulating HTML or XML. PHP has a number of inbuilt HTML parsers and for a robust solution you should use those instead, as a general rule.

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

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?