• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

parse url

0
rgb192
Asked:
rgb192
1 Solution
 
ropennerCommented:
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

0
 
rgb192Author Commented:
Doesn't work
0
 
ropennerCommented:
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Ray PaseurCommented:
I do not understand what you mean by "anchor portion" but PHP has a built-in function to do this.
http://www.laprbass.com/RAY_temp_rgb192.php
Outputs something like:
Array
(
    [scheme] => HTTP
    [host] => website.com
    [path] => /folder/folder/page.php
    [query] => car=Ford&size=compact
    [fragment] => top
)
<?php // RAY_temp_rgb192.php
$url = 'HTTP://website.com/folder/folder/page.php?car=Ford&size=compact#top';
$arr = parse_url($url);
echo "<pre>";
print_r($arr);

Open in new window

0
 
maricksvilleCommented:
Of the supplied URL which part do you want to access:

HTTP://website.com/folder/folder/page.php?car=Ford&size=compact#top
0
 
rgb192Author Commented:
thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now