-1

eg. this string:

$foo = 'this_is_a_string';

Now I want to extract the string that comes after the second _ symbol, no matter how long the string is or how many _ symbols it contains.

this should be the result:

"a_string"

  • [`strpos()`](https://www.php.net/manual/en/function.strpos) twice, using the result from the first run as the third argument for the second run, then [`substr()`](https://www.php.net/manual/en/function.substr). – Sammitch Jun 17 '22 at 19:13
  • https://stackoverflow.com/questions/46268571/returning-a-string-after-the-second-occurrence-of-a-character-and-before-the-las – Marshall C Jun 17 '22 at 19:14

1 Answers1

0
<?php
$foo = 'this_is_a_string';
var_dump(substr($foo,stripos($foo,'_',stripos($foo,'_')+1)+1));
?>