2

I have a variable which stores the URL links for example:

$link = "https://www.google.no/search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example"

$link = "http://www.example.com/forums/showthread.php?37dsf624-Get-everything-after-the-domain-name"

How do i extract the evrything which is after the domain name. for example i want from

$link = "https://www.google.no/search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example"

to extract

search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example

and from

$link = "http://www.example.com/forums/showthread.php?37dsf624-Get-everything-after-the-domain-name"

to extract

/forums/showthread.php?37dsf624-Get-everything-after-the-domain-name
0

2 Answers 2

11

look at the php function parse_url and parse_str

http://php.net/manual/de/function.parse-url.php

http://php.net/manual/de/function.parse-str.php

you can extract everything from your url with this.

$link = "https://www.google.no/search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example";

$parsedUrl = parse_url($link);
parse_str($parsedUrl['query'], $parsedQuery);
print_r($parsedUrl);
print_r($parsedQuery);

Array
(
    [scheme] => https
    [host] => www.google.no
    [path] => /search
    [query] => num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example
)
Array
(
    [num] => 100
    [newwindow] => 1
    [safe] => off
    [site] => 
    [source] => hp
    [q] => example
    [oq] => example
)
0
0
<?php 
$array[]= parse_url("https://www.google.no/search?num=100&newwindow=1&safe=off&site=&source=hp&q=example&oq=example");

$reqstring="{$array[0]['path']}?{$array[0]['query']}";
echo $reqstring;

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.