Page 1 of 1

Find http:// oder https:// and return rest of string

Posted: Tue Aug 23, 2005 4:29 am
by visionmaster
Hello together,

I would like to find http:// oder https:// in a string and if one of the two is matched, return rest of string.

Examples:
http://www.devnetwork.net => http://www.devnetwork.net
https://www.devnetwork.net => http://www.devnetwork.net

Finding the patterns ist not the problem. But how can I return the rest of the string, if there ist a match. I guess backreferences is the solution, but I'm a newbie in backreferences...

Code: Select all

if (preg_match('/(http|https):\/\//', $row->url)) {
						
}
else {

}


Thanks for your help!

Posted: Tue Aug 23, 2005 5:36 am
by anjanesh

Code: Select all

$url = "https://www.devnetwork.net";
if (preg_match("/(http|https):\/\/(.*?)$/i", $url, $matches) > 0)
 echo $matches[2];