Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: Parsing Problem

  1. #1
    New Coder
    Join Date
    Feb 2012
    Location
    Richardson
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Parsing Problem

    Hello all:

    I'm asked to do an assignment to parse all image from a html file.

    After researching from websites, I came up with following code:
    PHP Code:
    /(<img).*(srcs*=s*"([a-zA-Z0-9\.;:\/\?&=\-_|\r|\n]{1,})")/isxmU 
    Then I used this regex with my code to capture link of image file. But nothing showed up in output. Is there any simple regex to parse every image link from any html file?

  • #2
    New Coder
    Join Date
    Sep 2011
    Location
    USA
    Posts
    27
    Thanks
    3
    Thanked 1 Time in 1 Post
    Quote Originally Posted by A1dfw View Post
    Hello all:

    I'm asked to do an assignment to parse all image from a html file.

    After researching from websites, I came up with following code:
    PHP Code:
    /(<img).*(srcs*=s*"([a-zA-Z0-9\.;:\/\?&=\-_|\r|\n]{1,})")/isxmU 
    Then I used this regex with my code to capture link of image file. But nothing showed up in output. Is there any simple regex to parse every image link from any html file?
    Your regex seems ok to me. Could you paste rest part of your code and the html too?

  • #3
    New Coder
    Join Date
    Feb 2012
    Location
    Richardson
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    For some reason, I can't paste the code of my project. Let's consider the html code of yahoo.com. I just wanted to know how all image link can be parsed from particular link? Is there any better regex or not?

  • #4
    New Coder
    Join Date
    Sep 2011
    Location
    USA
    Posts
    27
    Thanks
    3
    Thanked 1 Time in 1 Post
    Quote Originally Posted by A1dfw View Post
    For some reason, I can't paste the code of my project. Let's consider the html code of yahoo.com. I just wanted to know how all image link can be parsed from particular link? Is there any better regex or not?
    Try this, it should work since it worked in several test projects of mine before
    PHP Code:
    $image preg_match('#^[a-z]\w+/\w+[.](jpg)$#im',$str);
    print_r($image); 

  • Users who have thanked cyberhostbd for this post:

    A1dfw (02-25-2012)

  • #5
    New Coder
    Join Date
    Feb 2012
    Location
    Richardson
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It worked with one problem. I will get back to you soon if I need further assistance.

  • #6
    New Coder
    Join Date
    Sep 2011
    Location
    USA
    Posts
    27
    Thanks
    3
    Thanked 1 Time in 1 Post
    Quote Originally Posted by A1dfw View Post
    It worked with one problem. I will get back to you soon if I need further assistance.
    It worked with one problem! What problem is that? If there were a problem, it shouldn't work at all. Anyway, I'm glad that it worked.

  • #7
    New Coder
    Join Date
    Feb 2012
    Location
    Richardson
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cyberhostbd View Post
    It worked with one problem! What problem is that? If there were a problem, it shouldn't work at all. Anyway, I'm glad that it worked.
    I meant- no problem. Typo mistake. Thank you for your guidance. Btw, I googled a lot about php parsing and collected great resources. Hopefully, I won't come up with this type of easy questions in future unless I get stuck somewhere in my work.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •