[wd_asp elements=’search’ ratio=’100%’ id=1]

Trim left and right strings – Take off letters – PHP

5th July 2013

Php - Strings

php codehaven

Adjust the length of strings in PHP


$var ="abcdefgh";
$var1 = substr($var, 3); //takes of first 3
$var1 is now "defgh"

$var2 = substr_replace($var ,"",-3); //takes off last 3
$var2 is now "abcde"

Get first 3 characters

$var3 = substr($var, 0, 3);
$var3 is now "abc"