Search code examples
phpstringtruncatestrpos

Crop string after 2nd full stop


In PHP, I'd like to crop the following sentence:

"Test 1. Test 2. Test 3."

and transform this into 2 strings:

"Test 1. Test 2." and "Test 3."

How do I achieve this?

Do I use strpos?

Many thanks for any pointers.


Solution

  • Something like that?

    $str = 'Test 1. Test 2. Test 3.';
    $strArray = explode('.', $str);
    $str1 = $strArray[0] . '. ' . $strArray[1] . '.';
    $str2 = $strArray[2] . '.';