因为只显示带有 substr() 的文本
As only display text with substr()
根据资料我把一篇HTML自带的文章保存为<br>, <table> ... etc. ....
示例:
<tr>
<td style="width:50%;text-align:left;">Temas nuevos - Comunidad</td>
<td class="blocksubhead" style="width:50%;text-align:left;">Temas actualizados - Comunidad Temas actualizados - Comunidad</td>
</tr>
我想要的是在另一个屏幕上使用 substr() 显示文章摘要,我的问题是我无法打印我想要的内容,并且首先打印 html 代码 eta。
示例:echo substr($row["news"], 0, 20);
它正在打印前 20 个字符,它只在浏览器中显示:
<td style="width:50%;text-align:l<td/>
我想要的是,它只显示文本并丢弃它具有的 html 代码
使用strip_tags()
从字符串中去除html等...
所以:echo substr(strip_tags($row["news"]), 0, 20);
http://php.net/manual/en/function.strip-tags.php
您可以也可以使用preg_replace()
来匹配和替换任何看起来像标签的东西:)
strip_tags() 函数从 HTML、XML 和 PHP 标签中剥离字符串。
//remove the html from the string.
$row["news"] = strip_tags($row["news"]);
//getting the first 20 character from the string and display as output.
echo substr($row["news"], 0, 20);
根据资料我把一篇HTML自带的文章保存为<br>, <table> ... etc. ....
示例:
<tr>
<td style="width:50%;text-align:left;">Temas nuevos - Comunidad</td>
<td class="blocksubhead" style="width:50%;text-align:left;">Temas actualizados - Comunidad Temas actualizados - Comunidad</td>
</tr>
我想要的是在另一个屏幕上使用 substr() 显示文章摘要,我的问题是我无法打印我想要的内容,并且首先打印 html 代码 eta。
示例:echo substr($row["news"], 0, 20);
它正在打印前 20 个字符,它只在浏览器中显示:
<td style="width:50%;text-align:l<td/>
我想要的是,它只显示文本并丢弃它具有的 html 代码
使用strip_tags()
从字符串中去除html等...
所以:echo substr(strip_tags($row["news"]), 0, 20);
http://php.net/manual/en/function.strip-tags.php
您可以也可以使用preg_replace()
来匹配和替换任何看起来像标签的东西:)
strip_tags() 函数从 HTML、XML 和 PHP 标签中剥离字符串。
//remove the html from the string.
$row["news"] = strip_tags($row["news"]);
//getting the first 20 character from the string and display as output.
echo substr($row["news"], 0, 20);