Created
March 12, 2019 12:27
-
-
Save melvinstanly/6bc889a6336cca23ff31bbadd04554af to your computer and use it in GitHub Desktop.
Php equivalent for .slice() of jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function strSlice($str, $start, $end) { | |
$end = $end - $start; | |
return substr($str, $start, $end); | |
} | |
$name = 'migthegreek'; | |
// Get substr from index 3 to 6 | |
echo strSlice($name, 3, 6); | |
// Outputs 'the' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment