大佬教程收集整理的这篇文章主要介绍了php-获取字符串的前200个字符,但不要在末尾破坏HTML标记,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
编辑:关键点是关于获取前200个字符并关闭所有未打开的标签.
我目前正在通过DOM对象从其他网站加载文章(其他网站没有RSS).我想对该文章做一个“预览”,但这是我的问题:
>我不控制文章的编写方式,因此,它似乎总是位于第二个TR的表中(它们使用CMS,而且很乱-请参见下面的示例).
>他们有很多HTML标记,我不想公开.
>我需要保留HTML格式,我知道它很丑陋,但是非常适合我的页面.
不是我的代码(以法语表示抱歉):
<table>
<TR >
<TD class='Normal' valign="top" colspan="2" style="padding-bottom:15px;">13-01-2012 <b>Water-polo – Championnat pan-pacifique<b ></TD>
</TR><TR >
<TD class='Normal' valign="top"><span class="HeadtitleNews"> Les Canadiennes disputeront le bronze aux Chinoises</span> <img src='http://www.sportcom.qc.ca/Portals/0/2011WaterpoloF.jpg' width='165' align='right' class='imgAnnouncementCss'><div style="margin: 0in 0in 0pt"><span style="font-family: Tahoma; font-size: 10pt">Montréal, 13 janvier 2012 (Sportcom) – L’équipe féminine canadienne de water-polo a remporté une victoire écrasante de 19-3 face au Brésil, vendredi, au Championnat pan-pacifique de Melbourne, en Australie. Les Canadiennes se sont ainsi assurées de participer au match pour la médaille de bronze contre les Chinoises. </span></div>
<div style="margin: 0in 0in 0pt"> </div>
<div style="margin: 0in 0in 0pt"><span style="font-family: Tahoma; font-size: 10pt">La Montréalaise <strong>Sophie</strong></span><strong><span style="font-family: Tahoma; font-size: 10pt"> Baron-La Salle</span></strong><span style="font-family: Tahoma; font-size: 10pt"> a marqué quatre buts dans la victoire. </span></div>
<div style="margin: 0in 0in 0pt"> </div>
谢谢.
解决方法:
<?PHP
$your_String_without_tags = Strip_tags($your_String);
$your_200_char_String = substr($your_String_without_tags, 0, 200);
?>
Close open HTML tags in a string
以上是大佬教程为你收集整理的php-获取字符串的前200个字符,但不要在末尾破坏HTML标记全部内容,希望文章能够帮你解决php-获取字符串的前200个字符,但不要在末尾破坏HTML标记所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。