Jump to content

extract the middle part of this url


chetankchandak
 Share

Go to solution Solved by chetankchandak,

Recommended Posts

From  http://www.shopclues.com/1862-hey-dude-footwear.html%3Fref%3D20 I want the output to display 

shopclues.com/1862-hey-dude-footwear.html

 

data after . and before %

I think i am missing something in the preg_match

 

Plz help

<?php
// get host name from URL
preg_match('@^(?:http://)?([^%]+)@i',
    "http://www.shopclues.com/1862-hey-dude-footwear.html%3Fref%3D20", $matches);
$host = $matches[1];

// get last two segments of host name
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";
 ?>
Link to comment
Share on other sites

  • Solution

thanks but solved it from other way 

<?php
// get host name from URL
preg_match('@^(?:http://) ?([^%]+)@i',
    "http://www.shopclues.com/1862-hey-dude-footwear.html%3Fref%3D20", $matches);
$host = $matches[1];
echo "<br>";
$site_url=str_replace("www.","",$host);
echo $site_url;
 ?>
Link to comment
Share on other sites

try using parse_url() php function

You really should be using the parse_url function.

Some guidance for the OP about using parse_url() for his particular needs wouldn't go amiss, guys; especially since parse_url() would only go a small way towards resolving the question posed.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.