我有像
这样的内容<p>
<strong><span style="font-family: monospace; white-space: pre-wrap; ">Description:Getting Started contains a list of tasks you might want to perform when you set up your computer. Tasks in Getting Started include: Dnescription:Getting Started contains a list of tasks you might want to perform when you set up your computer. Tasks in Getting Started include:</span></strong></p>
现在我想只选择50个字符,只有
说明:“入门”包含您在设置计算机时可能要执行的任务列表。入门任务包括:
它应该排除标签和 如何实现这个????
答案 0 :(得分:0)
如果您只想删除标记,可以使用strip_tags($text);
echo substr(str_replace(" ","",strip_tags($yourText),0,50))
会打印出您期望的内容。
答案 1 :(得分:0)
您应该在PHP中执行以下示例
$data = '<b>Description: </b> Getting Started contains a list of tasks you might want to perform when you set up your computer. Tasks in Getting Started include:'
// remove html tags
$data = strip_tags($data);
// remove all
$data = preg_replace("/\[(.*?)\]\s*(.*?)\s*\[\/(.*?)\]/", "[$1]$2[/$3]", html_entity_decode($data));
OR
$data = trim(str_replace(' ','',$data));
//limit characters
$data = substr($data,0,50);
现在您可以在html
中的任何位置回显此数据答案 2 :(得分:0)
$tmp = "<p><strong><span style=\"font-family: monospace;
white-space: pre-wrap;\">Description:Getting Started contains a list
of tasks you might want to perform when you set up your computer. Tasks
in Getting Started include:
Dnescription: Getting Started contains a list of tasks you might want
to perform when you set up your computer. Tasks in Getting Started
include:</span></strong></p>";
$tmp = preg_replace("/&#?[a-z0-9]{2,8};/i","",$tmp);
$final = substr(strip_tags($tmp),0,50);
修改强>
如上所述,这不会删除html实体。所以我从How to remove html special chars?
借了一个正则表达式现在,$final
包含您想要的输出。