preg_match and regex - Help please!

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
busin3ss
Forum Newbie
Posts: 6
Joined: Mon Sep 25, 2006 4:58 pm

preg_match and regex - Help please!

Post by busin3ss »

Hey! I have this issue... And it's driving me nuts! Everything I've tried doesn't work!

I want to preg_match from this line:

Code: Select all

<media:content url="http://static.flickr.com/87/252318706_4640fb66de_o.jpg" type="image/jpeg" height="520" width="426"/>
The url:

Code: Select all

http://static.flickr.com/87/252318706_4640fb66de_o.jpg
And I've tried

Code: Select all

preg_match("/src=\"http:\/\/static.flickr.com\/(.*).jpg\"/si",$rss,$r);
But It doesnt work...
Anyone could point me in the right direction?

Thanks in advanced!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

<media:.*?url="(http://.*?\.jpg)".*?>
Will match

Code: Select all

<media:content url="http://static.flickr.com/87/252318706_4640fb66de_o.jpg" type="image/jpeg" height="520" width="426" / >
busin3ss
Forum Newbie
Posts: 6
Joined: Mon Sep 25, 2006 4:58 pm

Post by busin3ss »

Thanks! Just a quick question, and if I just want to match just the url, not the whole tag?

Thanks in advanced!
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

You're harvesting copyrighted flickr-photos?
busin3ss
Forum Newbie
Posts: 6
Joined: Mon Sep 25, 2006 4:58 pm

Post by busin3ss »

Ehmm... Nope... I just want to put in the sidebar of my blog my flickr images, but I'm trying to do it with my own code
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Ah! Why not use their API? Saves you the parsing, is more comfortable and probably faster.
busin3ss
Forum Newbie
Posts: 6
Joined: Mon Sep 25, 2006 4:58 pm

Post by busin3ss »

I already have a script that uses their API, and another one that uses MagPie RSS... But I want to do it with regex and preg_match this time, can you please put back the code that was already posted

Thanks in advanced!
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

it's back.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

++example of overzelous moderator
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

astions wrote:++example of overzelous moderator
:roll: There were reasons it was removed originally, and it was put back promptly. I don't think that statement was necessary.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

d11wtq, I really respect your judgement and opinion, but I really feel that this is a good example of a moderator jumping the gun. Usually it's a different moderator, but never-the-less, for one to make an assumption that this was going to be used for illicit purposes is a bit out of line. But even if the user was planning on using it for illicit purposes, who are we to become the judge, jury and executioner?

He asked how to parse a string and he got an answer. The string he gave could have been a psuedo string. It could have said <media: microsoft blah>. I'm sorry, but I think devnet is starting to get a bit out of line. Would that other php forum site block stuff like that?

And then, add to that, this is a brand new forum member. What a warm welcome he received eh.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Forum Rules wrote:9. Warez, copyright violation, or promotion of any other illegal activity may NOT be linked or expressed or posted in any form.
If anything, I was too lenient.

So as not to add more meta-discussion to this: if there is need for further discussion, I suggest to either (in this order) PM, post on the Forum Rules discussion thread or open a new thread in General Discussion.
Post Reply