Hi,
My company has a series of websites with very similar domain names based on the city. The format for these is http://locksmithdallas.com
or http://locksmithgarland.com
. I'd like to figure out a way to interpret Dallas and Garland out of the domain names in php. I'm a noob at regex, so I could really use some help!
views:
59answers:
3
+3
A:
if (preg_match('/locksmith([^.]*)\.com/', $url, $matches)) {
$city = $matches[1];
}
Gavin Miller
2009-08-26 23:12:29
+1
A:
if (preg_match('#locksmith([^.]*)\.com#', $url, $matches)) {
//has been found
var_dump($matches);
}
André Hoffmann
2009-08-26 23:15:15
+1
A:
This one's simple but you can elaborate from there:
http://locksmith(?<name>[a-zA-Z]+)\.com
That will give you a named group called "name" where you can grab the text after locksmith and before .com.
HackedByChinese
2009-08-26 23:15:28
Thanks for that, I'm still learning and examples are one of the best ways to do it!
2009-08-26 23:24:47