Search code examples
phpstringtext-extraction

Get substring before a specified substring


$title = 'the.test.hd.part12';

I need to keep the characters up until it finds the word "part".

Should return - the.test.hd.


Solution

  • echo strstr($title, 'part', true); // As of PHP 5.3.0