简体   繁体   中英

Display Joomla Intro Article without <p> tag

I'm customizing the layout of category blog view for my template and I need to display the article intro text without the

tag. In my custom file "blogalternativelayout_item.php", I use:

<?php echo substr(($this->item->introtext),0,75); ?>

Anyway this renders the introtext as

<p>Lorem ipsum etc...</p>

How could I do to remove the paragraph tags? Thanks in advance.

You can use php strip_tags() function. eg;

echo strip_tags($this->item->introtext);

the code above will strip all the html tags in introtext.

If you want to strip tags except tags, then you can put it like this:

echo strip_tags($this->item->introtext, "<a>");

You have to use regex to achieve this task

<?php 

$text = substr(($this->item->introtext),0,75); 
//get the contents inside <p> tag using this regex
$result = preg_replace('/<p\b[^>]*>(.*?)<\/p>/i', '', $text);

echo $result;

?>

Thanks to both suggestions. I've created this code and working:

<?php
$desctrunc = substr(($this->item->introtext),0,75);
$desc = strip_tags($desctrunc);
echo $desc . '...';
?>

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM