maddali Posted February 15, 2010 Share Posted February 15, 2010 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 More sharing options...
teamatomic Posted February 15, 2010 Share Posted February 15, 2010 That function is only part of whats needed. Notice the use of objects. $post->post_content, I'd sat that converts form data. The function I think comes from some class that is to grab a remote page. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/192082-passing-url-to-get-the-image/#findComment-1012362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.