In smarty, strip_tags first filters the html tags and then truncate intercepts the article and uses it.

PHP中文网
Release: 2023-02-28 19:48:01
Original
1167 people have browsed it

strip_tags() function strips HTML, XML and PHP tags.

strip_tags() function strips HTML, XML and PHP tags.

The code is as follows:

<?php echo strip_tags(“Hello <b>world!</b>”); ?>
Copy after login

You can use strip_tags in smarty to remove html tags, including any content between < >.
For example:
index.php:

The code is as follows:

$smarty = new Smarty; 
$smarty->assign(‘articleTitle&#39;, “Blind Woman Gets <span style=”font-family: &amp;amp;”>New Kidney</span> from Dad she Hasn&#39;t Seen in <strong>years</strong>.”); 
$smarty->display(‘index.tpl&#39;);
Copy after login

index.tpl:

The code is as follows:

{$articleTitle} 
{$articleTitle|strip_tags}
Copy after login

Output result:

The code is as follows:

Blind Woman Gets <span style=”font-family: helvetica;”>New Kidney</span> from Dad she Hasn&#39;t Seen in <strong>years</strong>. 
Blind Woman Gets New Kidney from Dad she Hasn&#39;t Seen in years.
Copy after login

Article interception:

The code is as follows:

{$article.content|truncate:35:”…”:true}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!