...

View Full Version : Parsing Problem



A1dfw
02-25-2012, 08:06 AM
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:

/(<img).*(src\s*=\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?

cyberhostbd
02-25-2012, 08:08 AM
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:

/(<img).*(src\s*=\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?

A1dfw
02-25-2012, 08:15 AM
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?

cyberhostbd
02-25-2012, 08:22 AM
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

$image = preg_match('#^[a-z]\w+/\w+[.](jpg)$#im',$str);
print_r($image);

A1dfw
02-25-2012, 08:25 AM
It worked with one problem. I will get back to you soon if I need further assistance.

cyberhostbd
02-27-2012, 08:55 AM
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.

A1dfw
02-27-2012, 09:07 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum