Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

parse url

Posted on 2011-09-23
6
Medium Priority
?
247 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

618 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