Jump to content

passing url to get the image


maddali

Recommended Posts

Hi folks,

 

I've googled for a function to get an image from a url and that displays the first image in the webpage...I've managed to get a code that does the sam ething....however,I'm confused on where do we provide an url for this function to catch that image....

 

 

function catch_that_image() {

  global $post, $posts;

  $first_img = '';

  ob_start();

  ob_end_clean();

  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);

  $first_img = $matches [1] [0];

 

  if(empty($first_img)){ //Defines a default image

    $first_img = "/images/default.jpg";

  }

  return $first_img;

}

 

 

When I try to access the I'm trying to call this function from a file say catchimage.php with the echo function

 

<?php echo catch_that_image() ?>,I get the same function as an o/p in the webpage....

 

 

Link to comment
https://forums.phpfreaks.com/topic/192082-passing-url-to-get-the-image/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.