Ouzo\Utilities\Strings::substringBefore PHP Method

substringBefore() public static method

Gets the substring before the first occurrence of a separator. The separator is not returned.
public static substringBefore ( string $string, string $separator ) : string
$string string
$separator string
return string
    public static function substringBefore($string, $separator)
    {
        $pos = mb_strpos($string, $separator);
        return $pos !== false ? mb_substr($string, 0, $pos) : $string;
    }

Usage Example

Beispiel #1
0
 /**
  * @test
  */
 public function shouldReturnNullForNull()
 {
     //given
     $string = null;
     //when
     $result = Strings::substringBefore(null, ',');
     //then
     $this->assertNull($result);
 }