Stringy\Stringy::startsWith PHP Method

startsWith() public method

Returns true if the string begins with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
public startsWith ( string $substring, boolean $caseSensitive = true ) : boolean
$substring string The substring to look for
$caseSensitive boolean Whether or not to enforce case-sensitivity
return boolean Whether or not $str starts with $substring
    public function startsWith($substring, $caseSensitive = true)
        $substringLength = \mb_strlen($substring, $this->encoding);
        $startOfStr = \mb_substr($this->str, 0, $substringLength, $this->encoding);
        if (!$caseSensitive) {
            $substring = \mb_strtolower($substring, $this->encoding);
            $startOfStr = \mb_strtolower($startOfStr, $this->encoding);
        return (string) $substring === $startOfStr;

Usage Example

Example #1
  * {@inheritdoc}
 public function startsWith($substring, $caseSensitive = true)
     return (bool) parent::startsWith($substring, $caseSensitive);
All Usage Examples Of Stringy\Stringy::startsWith