dongya767979565 2016-08-18 18:04
浏览 20
已采纳

某个字符后删除html代码php [关闭]

Question: I have full html code inserted into mysql database. I want to remove everything after Product Description. How would I do it?

<p>hjfsdgfsgdfjsdgfjgdsjfgsdjgfjsdgf </p>
<p>Product Description</p>

I want to store into the database again with the html format.

  • 写回答

3条回答 默认 最新

  • dongtaotao19830418 2016-08-18 18:33
    关注

    Answering to the question proposed in the comments of your original question, you can do something like this:

    preg_replace("/<div class=\"ui-box product-description-main\".*/sm", " ",$your_html_goes_here);
    

    This removes everything after the div element with classes 'ui-box' and 'product-description-main'.

    By the same token, answering your original question is fairly simple:

    preg_replace("/(<p>Product Description<\/p>).*/sm", "$1", $your_html_goes_here);
    

    This removes everything after the paragraph 'Product Description'. If you need more information about the regex proposed in my answer,let me know.

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改