我需要删除从 Petfinder API 返回的描述中的所有 HTML 标记,但我似乎无法弄清楚如何。
$data['description']
保存返回的描述。我在源文件中看到的是这样的......
<div>some text that gets returned</div>
我试过用strip_tags
,我试过用html_entity_decode
,但标签不会消失!
我需要剥离标签,以便截断描述。
有人有想法么?
$data['description'] = (string)$pet->description;
$description = $data['description'];
$description = htmlentities($description);
$description = html_entity_decode($description);
$description = strip_tags($description);
$description = substr($data['description'],0,300);
$description = substr($description,0,strrpos($description,' '));
$description = $description."...";
echo "<span style='text-align: justify; margin: 10px 0px;'>".$description."</span>";