?
Solved

parse url

Posted on 2011-09-23
6
Medium Priority
?
245 Views
Last Modified: 2012-05-12
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:ropenner
ID: 36589178
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
 

Author Comment

by:rgb192
ID: 36589260
Doesn't work
0
 
LVL 8

Expert Comment

by:ropenner
ID: 36589769
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.

 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 36590449
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
 
LVL 2

Expert Comment

by:maricksville
ID: 36592010
Of the supplied URL which part do you want to access:

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

Author Closing Comment

by:rgb192
ID: 36592648
thanks
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question