WebDesignerDeveloper Posted August 19, 2013 Share Posted August 19, 2013 Hi all I want to fetch last characters after........... "=" sign ....... http://www.abc.com/index.php?site=new I want to fatch only........ new http://www.abc.com/i...p?site=previous I want to fatch only........ previous Thanks http://www.idea-ads.com Quote Link to comment Share on other sites More sharing options...
requinix Posted August 19, 2013 Share Posted August 19, 2013 One thread for a question. Just one thread. Don't need to post three of them in different forums. So you're in the index.php script and want to get the "new" from the URL? $_GET echo $_GET["site"];If you're not sure the "site=next" is even present in the URL, which it might not be, then use isset to check if it is before you try to use it. if (isset($_GET["site"])) { $site = $_GET["site"]; // ... } else { // wasn't given } Quote Link to comment Share on other sites More sharing options...
WebDesignerDeveloper Posted August 19, 2013 Author Share Posted August 19, 2013 One thread for a question. Just one thread. Don't need to post three of them in different forums. So you're in the index.php script and want to get the "new" from the URL? $_GET echo $_GET["site"];If you're not sure the "site=next" is even present in the URL, which it might not be, then use isset to check if it is before you try to use it. if (isset($_GET["site"])) { $site = $_GET["site"]; // ... } else { // wasn't given } No no, actually, http://www.abc.com/index.php?site=new ... is a single string, i want to explode this... I want to devide this in two parts... breaking through "=" sign Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 19, 2013 Share Posted August 19, 2013 Have you looked into explode()? http://php.net/manual/en/function.explode.php Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 19, 2013 Share Posted August 19, 2013 Or, if you ONLY need the text after the equal sign and don't need the part before, you can use strpos() and substr() $value = substr($input, strpos($input, '=')); Although, you could also just use strrchr(), but that would include the equal sign in the result and require another step as well. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 19, 2013 Share Posted August 19, 2013 Or if you need more, maybe parse_url() and parse_str()? Quote Link to comment Share on other sites More sharing options...
Solution .josh Posted August 19, 2013 Solution Share Posted August 19, 2013 $url = "http://www.abc.com/index.php?site=new"; $parts = parse_url($url); parse_str($parts['query'],$query); echo $query['site']; // this will have your value Quote Link to comment Share on other sites More sharing options...
WebDesignerDeveloper Posted August 20, 2013 Author Share Posted August 20, 2013 $url = "http://www.abc.com/index.php?site=new"; $parts = parse_url($url); parse_str($parts['query'],$query); echo $query['site']; // this will have your value many thanks for your co-operation Quote Link to comment Share on other sites More sharing options...
WebDesignerDeveloper Posted August 20, 2013 Author Share Posted August 20, 2013 Or, if you ONLY need the text after the equal sign and don't need the part before, you can use strpos() and substr() $value = substr($input, strpos($input, '=')); Although, you could also just use strrchr(), but that would include the equal sign in the result and require another step as well. this includes "=" sign, which i don't want anyway many thanks for your answer Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 20, 2013 Share Posted August 20, 2013 this includes "=" sign, which i don't want anyway many thanks for your answer Then add 1 $value = substr($input, strpos($input, '=')+1); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.