How to get first an image in Joomla article?

In some specific cases, you need to get first an image in Joomla article. This guide will help you do that with a simple syntax. This is not the easiest way, but could you use regex to pull out the image from the intro-text if it’s not specifically given?

You’d need a pattern something like: <img\b[^>]+?src\s*=\s*[‘”]?([^\s'”?#>]+)

<?php
  // This is the Regex pattern from above.
  $pattern = '/<img\b[^>]+?src\s*=\s*[\'"]?([^\s\'"?#>]+)/'; 

  // Perform the search, matches will be stored in $matches
  preg_match($pattern, $item->introtext, $matches ); 

  echo "Image src is: " . $matches[1] . "\n";
?>
Share this :

Comments are closed.

Related post

Free Responsive Website templates

ThemeVina is Best site for free sharing and download Wordpress themes, Joomla templates, Responsive website templates and more HTML templates.

All template in Site are free. You can download and install for your site.

Contact us

  • Brand: Theme Vina
  • Email: admin@themevina.com
  • Website: www.themevina.com
  • Address: 367 Tran Hung Dao Street
  • Location: Thai Binh City, Thai Binh, Viet Nam

Newsletter