Test if String Starts With Certain Characters in PHP | CSS-Tricks

PHOTO EMBED

Fri May 29 2020 13:09:12 GMT+0000 (UTC)

Saved by @Amna #javascript #php

<?php 
  
function startsWith($string, $startString) { 
  $len = strlen($startString); 
  return (substr($string, 0, $len) === $startString); 
} 

// usage
echo startsWith("cat", "c"); // true
echo startsWith("dog", "x"); // false

?> 
content_copyCOPY

https://css-tricks.com/snippets/php/test-if-string-starts-with-certain-characters-in-php/