Bhumi Shah Bhumi Shah - 3 months ago 16
PHP Question

How to get String after needle in PHP?

I have string like below:

$str = '/test/test1/test2/test3/testupload/directory/';


now I want to fetch some specific string so tried:

strstr($str, 'test3');


But I want to fetch value after needle? How can i do?

Thanks.

Answer
$str = '/test/test1/test2/test3/testupload/directory/';        
$new_str = strstr($str, 'test3');
// Use this to get string after test3 
$new_str = str_replace('test3', '', $new_str); 
// $new_str value will be '/testupload/directory/'
Comments