Skip to content

Instantly share code, notes, and snippets.

@sergiois
Last active December 22, 2015 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergiois/6416344 to your computer and use it in GitHub Desktop.
Save sergiois/6416344 to your computer and use it in GitHub Desktop.
Función para coger y quitar la primera imagen del introtext de Joomla! (texto que va hasta el readmore)
<?php
// cogemos imagen de introtext
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $this->item->introtext, $src);
$first_img = $src[1][0];
if(!empty($src[1][0])){
echo '<div class="first_img"><img src="'.$src[1][0].'" alt="" /></div>';
}
// quitamos todas las imágenes de introtext
$re_cleanImages = '/<img[^>]*>/';
$myCleanHtml = preg_replace($re_cleanImages,'',$this->item->introtext);
$myCleanHtml = str_replace('<p></p>','',$myCleanHtml);
echo $myCleanHtml;
// quitamos solo la primera imagen de introtext
$myCleanHtml = preg_replace("/<img[^>]+\>/i", '',$this->item->introtextl, 1);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment