Thomshaw Posted April 17, 2012 Share Posted April 17, 2012 Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! Quote Link to comment https://forums.phpfreaks.com/topic/261093-return-string-after-and-including-needle-in-the-string-haystack/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2012 Share Posted April 17, 2012 You do realize that the sobi2Id value from the URL will be available as $_GET['sobi2Id'] ? What exactly are you trying to accomplish and what is the actual data you are trying to do it for? Quote Link to comment https://forums.phpfreaks.com/topic/261093-return-string-after-and-including-needle-in-the-string-haystack/#findComment-1338066 Share on other sites More sharing options...
MarPlo Posted April 17, 2012 Share Posted April 17, 2012 Hi, If you want to get the substring after 'sobi2Id=' in a dinamic string, try this example: $url = 'http://domain/page.php?sobi2Id=xyz'; if(preg_match('/sobi2Id=(.*)$/i', $url, $tag)) { echo $tag[1]; // xyz } But if the 'sobi2Id=' is part of current url, is better to use $_GET (as mentioned in the response above). if(isset($_GET['sobi2Id'])) echo $_GET['sobi2Id']; Quote Link to comment https://forums.phpfreaks.com/topic/261093-return-string-after-and-including-needle-in-the-string-haystack/#findComment-1338072 Share on other sites More sharing options...
Thomshaw Posted April 17, 2012 Author Share Posted April 17, 2012 Amazing guys thanks a lot, I'm trying to learn as I code and am just working out what everything is, means, and references. I hate being a noob! Quote Link to comment https://forums.phpfreaks.com/topic/261093-return-string-after-and-including-needle-in-the-string-haystack/#findComment-1338088 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.