获取有限的字符串 [英] Get limited word of a string
本文介绍了获取有限的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
html
标签的数据库中发现了一个sting。现在我不想整个字符串,我只是想要它的一部分,所以我用 substr()
来缩短我的字符串,现在它显示我的字符串 html
标签。我不想展示我的 html
标签。 我这样做:
<?php
$ content = $ news ['content'];
echo substr($ content,0,100)。...;
?>
结果:
< p class =boldp>全球总体雇主和制药行业第一...
欲望结果:
全球雇主总数和制药业第一位...
如何从我的字符串中移除这些 html
标记。
我不知道有没有人问过这个问题。我试图找到解决办法,但我没有找到任何东西。
解决方案
我认为您正在寻找 strip_tags :
echo strip_tags($ news ['content']);
So I am getting a sting from database which contains my html
tags. Now I don't want the whole string I just wanted some part of it so I used substr()
to short my string now it is showing my string with html
tags. I don't want to show my html
tags.
This is how I am doing:
<?php
$content = $news['content'];
echo substr($content, 0, 100)."...";
?>
Result:
<p class="boldp"> Overall Employer in World and No.1 in Pharmaceutical i...
Desire Result:
Overall Employer in World and No.1 in Pharmaceutical i...
How can I remove these html
tags from my string.
I don't know if anyone have asked this question or not. I tried finding solution to this but I didn't find anything.
解决方案
I think you are looking for strip_tags:
echo strip_tags($news['content']);
这篇关于获取有限的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文