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.
Regex question - Grabbed what I want but need usable format
Moderator: General Moderators
Re: Regex question - Grabbed what I want but need usable format
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
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
I'd want to haveRobert07 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
/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
Ok, so you can do something like this:
Unless the part you want to capture doesn't always start with /pphotos and have ? at the end...
Code: Select all
preg_match_all( '/(\/pphotos.*?)\?/', $property_photos, $matches);
foreach ($matches[1] as $url) {
// do something with the url
}