Bhumi Shah Bhumi Shah - 1 year ago 117
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?


Answer Source
$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/'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download