Jump to content

return string after and including $needle in the string $haystack


Thomshaw

Recommended Posts

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!

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.