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!

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

Archived

This topic is now archived and is closed to further replies.

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