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.

Pregreplace question

Discussion in 'PHP' started by crazyhorse, Jul 9, 2005.

  1. #1
    Hi

    Wondering whether anyone cant tell me what the diffence is between these three?

    Im using this in a rss feed to remove images.
     
    crazyhorse, Jul 9, 2005 IP
  2. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The first one will match img tags with attributes before and after the src attribute. The second one will only match img tags with attributes following the src attribute. The third one will match a tags with attributes following the tag.

    J.D.
     
    J.D., Jul 9, 2005 IP
  3. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #3
    And all three in a case-insensitive manner :)
     
    exam, Jul 9, 2005 IP
  4. crazyhorse

    crazyhorse Peon

    Messages:
    1,137
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #4
    crazyhorse, Jul 9, 2005 IP
  5. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is how one of the expressions will match, provided that your URL is inside an img tag that matches the expression.

    
    (<img (.*) src=\"http:\/\/images.****.com\/(.*                                      )>)
                     http: / /images.xxxx.com / f2/128/121/10841746/1097189840614_ps.gif
    
    Code (markup):
    If the img tag doesn't match, the URL won't matter, though. For example, if your img tag uses single quotes, as shown below, the expression won't match:

    (<img (.*) src=\"http:\/\/images.****.com\/(.*                                      )>)
    (<img      src= 'http: / /images.xxxx.com / f2/128/121/10841746/1097189840614_ps.gif'>)
    Code (markup):
    J.D.
     
    J.D., Jul 9, 2005 IP
  6. crazyhorse

    crazyhorse Peon

    Messages:
    1,137
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks im going to give it a try.
     
    crazyhorse, Jul 9, 2005 IP
  7. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you just want to remove images, wouldn't it be easier to do
    $str = preg_replace ("/<img[^>]*>/i", "", $str);
    PHP:
     
    exam, Jul 9, 2005 IP
  8. crazyhorse

    crazyhorse Peon

    Messages:
    1,137
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Will that remove all image? Cuase i dont want to remove all of them.
     
    crazyhorse, Jul 9, 2005 IP
  9. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #9
    Are there any tutorials on preg replace because I found the php.net tutorial on preg replace a little limited?
     
    Weirfire, Jul 11, 2005 IP
  10. nevetS

    nevetS Evolving Dragon

    Messages:
    2,544
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    135
    #10
    It's really a regular expression tutorial you need. preg_replace has pretty simple syntax.

    There are a million out there and they are all pretty intimidating at first read.

    http://www.tote-taste.de/X-Project/regex/

    http://www.mkssoftware.com/docs/man5/regexp.5.asp

    http://www.regexplib.com/ <-- has a testing page and a bunch of user contributed regexes - but unfortunately the testing page is .net and not php

    If I have some time tomorrow night, I'll throw up a php regex test page. Shouldn't take more than a few minutes, but I haven't found any online.
     
    nevetS, Jul 11, 2005 IP
  11. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #11
    I spent around 2 days on a certain members problem and found the syntax pretty hard to come to terms with.

    Thanks for the tutorials. Hopefully it shouldn't be too confusing. :)
     
    Weirfire, Jul 11, 2005 IP
  12. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Yes, it will remove all images.
     
    exam, Jul 11, 2005 IP
  13. crazyhorse

    crazyhorse Peon

    Messages:
    1,137
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thanks for the articles and the reply. This will give me something to read for in the weekends. I already know how to replace text. ;):p
     
    crazyhorse, Jul 11, 2005 IP