Get string between two other strings using PHP

January 24, 2024


function string_between_two_strings($str, $starting_word, $ending_word) {
     $subtring_start = strpos($str, $starting_word);
     $subtring_start += strlen($starting_word); 
     $size = strpos($str, $ending_word, $subtring_start) - $subtring_start; 
     return substr($str, $subtring_start, $size); 
}


Comments

There are no comments.


Comment on this Article

Your email address will never be published. Comments are usually approved within an hour or two. (to prevent spam)