Solved

parse url

Posted on 2011-09-23
6
244 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

695 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