• Resolved tom_de_schlong

    (@tom_de_schlong)


    Hi all I am using the following custom function to display a thumbnail automatically taken from the first image in the post and it works great.

    <?php // This Function Powers the thumbnail image that is used in my portfolio
    function return_ThumbNail($Thumb) {
    if (preg_match('/<img[^>]*>/',$Thumb,$Treffer)) {
    $Thumb = preg_replace('/(<img ).*(src=\'[^\']*\').*( \/>)/','$1$2$3',$Treffer[0]);
    $Thumb = preg_replace('/(.[^.]* \/>)/','.thumbnail$1',$Thumb);
    } else {
    $Thumb = false;
    }
    return $Thumb;
    }
    ?>

    I would like to extend this function to also pass the thumbnail the relevant “alt” text. I know this is probably simple but my php regular expression skills are not very good.

    Tom

Viewing 1 replies (of 1 total)
  • Thread Starter tom_de_schlong

    (@tom_de_schlong)

    Solved it myself

    <?php // This Function Powers the thumbnail image that is used in my portfolio
    function return_ThumbNail($Thumb) {
    if (preg_match('/<img[^>]*>/',$Thumb,$Treffer)) {
    $Thumb = preg_replace('/(<img ).(alt=\'\').*(src=\'[^\']*\').*( \/>)/','$1$2$3',$Treffer[0]);
    $Thumb = preg_replace('/(.[^.]* \/>)/','.thumbnail$1',$Thumb);
    } else {
    $Thumb = false;
    }
    return $Thumb;
    }
    ?>

    Tom

Viewing 1 replies (of 1 total)
  • The topic ‘Help needed extending custom function’ is closed to new replies.