Jump to content

preg_match help needed


DrTrans

Recommended Posts

No need for regex use parse_url

$url = 'http://blah.domain.com/directory/INFINITA/76/98/23';

$urlPath = parse_url($url, PHP_URL_PATH); // get the path from the url

$segment = explode('/', trim($urlPath, '/')); // explode the path into segments
echo $segment[1]; // get the second segment INFINITA

That would do every url that way that i pass to it.   basically 

 

what I'm trying to do is...

 

$text = " Im hanging out at http://blah.domain.com/directory/INFINITA/76/98/23" ;   

 

$text would return = "Im hanging out at INFINITA " with the "INFINITA" being hyperlinked to the original url.   

 

However,  if $text = "Go look at this thread: http://forums.phpfreaks.com/topic/284414"    it doesn't bother it. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.