Regex question - Grabbed what I want but need usable format

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

Moderator: General Moderators

Post Reply
ChrisF79
Forum Commoner
Posts: 26
Joined: Tue Apr 01, 2008 8:26 pm

Regex question - Grabbed what I want but need usable format

Post by ChrisF79 »

Greetings:

I have a Regex going out to my local real estate MLS and grabbing this bit of their site to add my listings to my own website automatically. I'm about to get the following into a variable called $property_photos:

\'/pphotos/54/209028054.101.jpg?id=418545,/pphotos/54/209028054.102.jpg?id=418545,/pphotos/54/209028054.103.jpg?id=418545,/pphotos/54/209028054.104.jpg?id=418545,/pphotos/54/209028054.105.jpg?id=418545,/pphotos/54/209028054.106.jpg?id=418545,/pphotos/54/209028054.107.jpg?id=418545,/pphotos/54/209028054.108.jpg?id=418545,\',\'www.sunshinemls.com\',\'8081\'

The URL's of the photos all have the same domain name so how can I get just them, without the id=418545? The other challenging part is that for each home, that ?id= part will have a different number so I can't just do a regex pointing to that.

I'm stumped on this one and would appreciate any help you could provide. Thanks for looking.
User avatar
Robert07
Forum Contributor
Posts: 113
Joined: Tue Jun 17, 2008 1:41 pm

Re: Regex question - Grabbed what I want but need usable format

Post by Robert07 »

Hello,
So you've captured the right section of the page that you want, but you want to pull out what, exactly? Can you print out what you want to pull from the string you posted? Is there one url to pull from that string or several?
Regards,
Robert
ChrisF79
Forum Commoner
Posts: 26
Joined: Tue Apr 01, 2008 8:26 pm

Re: Regex question - Grabbed what I want but need usable format

Post by ChrisF79 »

Robert07 wrote:Hello,
So you've captured the right section of the page that you want, but you want to pull out what, exactly? Can you print out what you want to pull from the string you posted? Is there one url to pull from that string or several?
Regards,
Robert
I'd want to have
/pphotos/54/209028054.101.jpg as the first value, then /pphotos/54/209028054.102.jpg then the 104.jpg and so on. I know the URL to append to the front of those paths so if I had an array with the paths to those jpegs, I'd be all set.
User avatar
Robert07
Forum Contributor
Posts: 113
Joined: Tue Jun 17, 2008 1:41 pm

Re: Regex question - Grabbed what I want but need usable format

Post by Robert07 »

Ok, so you can do something like this:

Code: Select all

 
preg_match_all( '/(\/pphotos.*?)\?/', $property_photos, $matches);
foreach ($matches[1] as $url) {
  // do something with the url
}
 
Unless the part you want to capture doesn't always start with /pphotos and have ? at the end...
Post Reply