php - reading and removing a substring in the most efficient way possible, like array_pop() but for sub strings -


i have string of following. in other words, may have "in morning" or "in evening" sometimes, may not have anything.

"bla bla in morning" or  "bla bla bla in evening" or  "bla bla bla" 

does php have function both isolate , remove sub string @ same time? $last_in_array = array_pop($arr); both saves last element $last_in_array , removes array @ same time. strings scenario i'm explaining. if not, what's efficient way this?

function string_pop(&$haystack, $needle) {     if (strpos($haystack, $needle) !== false) {         $haystack = str_replace($needle, "", $haystack);         return $needle;     }     return false; }  $string = "bla bla in morning"; $return = string_pop($string, " in morning");  var_dump($string); var_dump($return); 

output:

$string: string(7) "bla bla" $return: string(15) " in morning" 

Comments

Popular posts from this blog

forms - Secure PHP File Upload Script -

java - How do I override the spring framework version in Spring Batch? -

.net - Amazon EC2 API and Windows instances - any way to get drive letter assignment? -