-1

been on this for 2 hours now ...
$string = "https://www.example.com/?id=fsdf29512590125Agajgenaemganheji";
$end = strrchr($string, 'id='); // should return "fsdf29512590125Agajgenaemganheji"

echo $end;

only returns "i"

these work but not in larger url

$s = "https://www.example.com/?id=fsdf29512590125Agajgenaemganheji";

$firstPart = strtok( $s, 'id=' );

echo $firstpart;

tried also 'id\='

How to get everything after a certain character?

return id= value without id=

thank you

2 Answers2

1

If you don't mind using explode, you can try this

$string = explode("id=", "https://www.example.com/?id=fsdf29512590125Agajgenaemganheji", 2);

//$string[0] is https://www.example.com/? 
//$string[1] is fsdf29512590125Agajgenaemganheji
$id = $string[1];
Xun
  • 377
  • 1
  • 7
  • thank u it worked...... could u kindly assist me on my other question/. i tried to vote up it says i didnt have an enough rep. –  Mar 02 '23 at 05:57
  • https://stackoverflow.com/questions/75610803/php-dom-document-table-extract-not-working-by-class-name –  Mar 02 '23 at 05:57
  • You can accept the answer , I will take a look on your other question – Xun Mar 02 '23 at 06:04
  • oh i just notivced that button i clickeed accapt thank you. –  Mar 02 '23 at 11:11
1

You are trying to get the value of a parameter from a URL query string here, so you might as well use the functions that PHP explicitly provides for such purposes.

$url = "https://www.example.com/?id=fsdf29512590125Agajgenaemganheji";
$qs = parse_url($url)['query'];
parse_str($qs, $params);

var_dump($params['id']);
CBroe
  • 91,630
  • 14
  • 92
  • 150