0

这是获取提要的完整描述或内容的代码。但是,我只想要从一开始的前 15 个字符。我的代码正确吗?

</a> · <?php echo $item->get_description(str.substr(0,14)); ?>
4

2 回答 2

0

利用:

<?php echo substr($item->get_description($str),0,15); ?>
于 2013-09-03T06:28:31.147 回答
0

The problem is that you have HTML tags wrapping your text. So you actually have more than 15 characters including the HTML markup. You can strip the HTML out first using strip_tags() to get just 15 characters of text:

<?php echo substr(strip_tags($item->get_description($str)),0,15); ?>

Alternately if you want to keep the HTML markup, you would have to get the opening tag and then do a forward lookup of the ending tag, get the position in the string, and truncate anything after that.

于 2013-09-03T19:48:44.630 回答