1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to modify my php regular code?

Discussion in 'PHP' started by youlichika, Sep 3, 2010.

  1. #1
    I would like to adjust some pictures size. I used this code:

    <?php
    preg_match_all('/<img[^>]*width=\"[1-9]\d{2}\" height=\"[1-9]\d{2}\"[^>]*\/>/is', $s, $matches);
    $firstimg = $matches[0][0];
    $newimg = preg_replace('/width=\"\d+\" height=\"\d+\"/', 'width="300" height="200"', $firstimg);
    echo $newimg;
    ?>

    But it can not show all the pictures, when the picture rule is <img src="" alt="" title="" /> There is no width and height, it can not work,
    how to add a width and height to these kind of pictures?
    Thanks.
     
    youlichika, Sep 3, 2010 IP
  2. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #2
    Your better off using the GD library to resize the images in real time rather then pulling and squashing them like that.

    Read this for more information,

    http://php.net/manual/en/book.image.php

    Kind regards,

    Glen Hughes
     
    HuggyEssex, Sep 3, 2010 IP
  3. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #3
    An alternative would be, you could create a style class called img
     
    MyVodaFone, Sep 3, 2010 IP
  4. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What is your sample input?
     
    exam, Sep 3, 2010 IP