Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP strstr - The reverse method

I'm looking to get the same exact results as php strstr command (while it set to true) but in reverse order.

I know that I can simply reverse the string and use strstr and then reverse it again

but I was wonder if there is any internal php command for the task.

<?php

$myString = 'We don\'t need no education';

echo strstr($myString, ' ', true);

/*
 * output :
 * We
 *
 * I'm expecting to get :
 * education
 *
 */

exit;

?>

Very Simple !

like image 713
Steven Avatar asked Jan 10 '23 06:01

Steven


1 Answers

You have the function strrchr

$myString = 'We don\'t need no education';

echo strrchr($myString, ' ');
// output : ' education'

echo substr(strrchr($myString, ' '), 1);
// output : 'education'
like image 98
Alfwed Avatar answered Jan 12 '23 05:01

Alfwed