PHP and regex...

Discussion in 'PHP' started by lui2603, Jan 26, 2008.

  1. #1
    Does anyone know where I can find some simple tutorials on using regular expressions to scan HTML pages?

    I have been searching around for a long time but I only find tutorials explaining the basics of using preg_match to scan words or sentences but not HTML code..

    When I try to use what I learn on HTML code it outputs a blank array :/
     
    lui2603, Jan 26, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Well, firs off, it would be useful if you could post some examples and your current regex so we can try to fix it for you.


    Besides that, I keep suggesting this tutorial. http://www.phpvideotutorials.com/regex/ I think it's quite good.
     
    nico_swd, Jan 26, 2008 IP
  3. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the help!
    It is a great tutorial
     
    lui2603, Jan 26, 2008 IP
  4. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    http://www.ilovejackdaniels.com/cheat-sheets/regular-expressions-cheat-sheet/

    this is a great reference if you want to step your feet into the regular expressions...
     
    fairuz.ismail, Jan 26, 2008 IP
  5. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I was just about to post that link. I use it every time I have problems with a regexp.
     
    tamen, Jan 26, 2008 IP
  6. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks for the help :)
    I have got the cheat sheets printed next to me while im coding with regex ;)

    The reason it wasn't working before was I didn't realise I had to escape < > characters
     
    lui2603, Jan 27, 2008 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    You don't have to escape them. :)
     
    nico_swd, Jan 27, 2008 IP
  8. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #8
    hmm..
    After I did the script was working :/ lol
     
    lui2603, Jan 27, 2008 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    You must have changed something else too, because I've never escaped these characters and never had problems with them.
     
    nico_swd, Jan 27, 2008 IP
  10. adam2000

    adam2000 Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hi,

    Check out the following:

    http://www.regexbuddy.com/

    I am not an affiliate or anything like that. I've just found it useful when building regexp's. You should be able to post in your HTML code and build the regexp on the fly.

    Oops....just noticed they no longer offer a free trial (they used to), however it's still a very cheap tool for what it does in my opinion.
     
    adam2000, Jan 27, 2008 IP
  11. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I escaped </>'s for a long time too. But you don't have to escape them.
     
    tamen, Jan 27, 2008 IP