Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

parse url

Avatar of ropenner
ropenner
Flag of Canada image

the statement reads like:

^ match start of string
( I want the portion in brackets returned to me
.* anything
\/\/   then two slashes //
[^\/]*  anything that is not a slash
) end of the part I want returned
\/  then a slash

returns:  HTTP://website.com
<?php
$url = "HTTP://website.com/folder/folder/page.php?car=Ford&size=compact#top";
preg_match("/^(.*\/\/[^\/]*)\//",$url,$matches);
echo $matches[1];
//var_dump($matches);
?>

Open in new window

Avatar of rgb192

ASKER

Doesn't work
I am using php 5.3.3 in Ubuntu linux.  Works in a browser and on the command line.

Did it not return anything or did it return something that was not what you expected.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Of the supplied URL which part do you want to access:

HTTP://website.com/folder/folder/page.php?car=Ford&size=compact#top
Avatar of rgb192

ASKER

thanks