Skip to content

Instantly share code, notes, and snippets.

@MohamedLamineAllal
Created December 16, 2018 15:01
Show Gist options
  • Save MohamedLamineAllal/0924ccdc0cb16003d870c1cbe344598c to your computer and use it in GitHub Desktop.
Save MohamedLamineAllal/0924ccdc0cb16003d870c1cbe344598c to your computer and use it in GitHub Desktop.
PHP boiler plate (Important things that we use often)
<?php
// indexOf equivalent (get pos of a string within another)
int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
// http://php.net/manual/en/function.strpos.php
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment