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 Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/ 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 } Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/#findComment-1445769 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 Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/#findComment-1445828 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 Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/#findComment-1445829 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. Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/#findComment-1445833 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()? Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/#findComment-1445834 Share on other sites More sharing options...
.josh Posted August 19, 2013 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 Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/#findComment-1445835 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 Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/#findComment-1445909 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 Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/#findComment-1445910 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); Link to comment https://forums.phpfreaks.com/topic/281348-fetching-last-characters-after-sign/#findComment-1445917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.