Page 1 of 1

Regex question - Grabbed what I want but need usable format

Posted: Fri Oct 02, 2009 10:39 pm
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.

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

Posted: Fri Oct 02, 2009 11:36 pm
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

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

Posted: Fri Oct 02, 2009 11:51 pm
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.

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

Posted: Sun Oct 04, 2009 1:15 am
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...