Activity Stream
48,167 MEMBERS
6696 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 4 of 4
  1.     
    #1
    Member

    Default First Image Function

    Hi ...

    I was trying the below function to display only the first image from the content on the index page.

    Function :
    PHP Code: 
    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;

    But the above function displays the link to the image and does not load the image.

    Can someone tell me whats wrong with this function ??
    Matrix4u Reviewed by Matrix4u on . First Image Function Hi ... I was trying the below function to display only the first image from the content on the index page. Function : function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    tehMoviez.com 0Senes.com GeekFaceGames.com
    change
    Code: 
    return $first_img;
    to
    Code: 
    return "<img src=\"{$first_img}\" />";

  4.     
    #3
    Member
    Thanks Mate ...
    Worked Like a Charm

  5.     
    #4
    Member
    Website's:
    tehMoviez.com 0Senes.com GeekFaceGames.com
    any time mate

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [PHP] }else{ Function 3 parts
    By viruz99 in forum Web Application/Script Support
    Replies: 4
    Last Post: 17th Jan 2012, 01:33 AM
  2. [Help] Fix PHP function
    By m1rr0z in forum Web Development Area
    Replies: 0
    Last Post: 15th Apr 2011, 09:40 AM
  3. Kloxo zip function. Need help.
    By tres in forum Webmaster Resources
    Replies: 0
    Last Post: 12th Nov 2010, 09:59 AM
  4. [php] list_files() function
    By natsu90 in forum Web Development Area
    Replies: 2
    Last Post: 29th Sep 2010, 08:23 AM
  5. PHP Function (Link_Maker)
    By litewarez in forum Webmaster Resources
    Replies: 0
    Last Post: 2nd Dec 2008, 01:28 AM

Tags for this Thread

BE SOCIAL