phpstringsubstringtext-extraction

Get phrase from middle of a string between two particular characters


I want to extract a portion of a string between two points in a string.

My input string is {you: awesome; feeling good}

I want to get the words feeling good between ; and } using PHP.


Solution

  • $arr = explode(';', trim("{you: awesome; feeling good}", '{}'));
    $feel_good_string = trim($arr[1]);
    echo $feel_good_string;