简体   繁体   English

用PHP排除其中的特定html标记和内容

[英]Exclude specific html tag and content inside it with PHP

In my web application I want to display a short part of the body's content and for that I use PHP's mb_substr() function and that is OK and works fine. 在我的Web应用程序中,我想显示正文内容的一小部分,为此,我使用了PHP的mb_substr()函数,这样就可以正常工作了。 The problem is when that part of short content has a image tag that making mess in my design. 问题是,当短内容的那一部分具有图像标记时,这会使我的设计混乱。 I was wondering if PHP has any functions that exclude img tag with all content so I can use it before mb_substr() function, or I need to use javascript? 我想知道PHP是否有任何功能将img标签排除在所有内容之外,因此我可以在mb_substr()函数之前使用它,还是需要使用javascript?

The PHP function strip_tags will remove “HTML and PHP tags from a string” PHP函数strip_tags将删除“字符串中的HTML和PHP标签”

As you want to shorten some (HTML) text to a short text without HTML, that is probably what you are looking for!? 当您想将某些(HTML)文本缩短为没有HTML的短文本时,这可能就是您想要的!

You may have a problem with <img> right now, but other HTML tags may be an issue in the future, right? 您现在可能对<img>有问题,但是将来其他HTML标记可能会成为问题,对吧?

使用strip_tags并传递您希望保留的html标签...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM