Solved

parse url

Posted on 2011-09-23
6
240 Views
Last Modified: 2012-05-12
0
Comment
Question by:rgb192
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 108

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now