[筆記] startswith & endswith in php
`substr` usage:
```php
substr ( string $string , int $start [, int $length ] ) : string
```
```php
function startsWith($haystack, $needle) {
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
```
reference:
- [stackoverflow](https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php)
- [php documention](https://www.php.net/manual/en/function.substr.php)
2019-05-18 18:31:40
留言
Last fetch: --:--
現在還沒有留言!