0 points

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


dashboard

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

Posted 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_copy Copy

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