...

View Full Version : LEFT/RIGHT for php?



angst
04-07-2006, 10:12 PM
hello,
I'm still new to php, and I'm wondering how to work with strings.
in ASP to I could use Len, Left, Right, Instr.

what can I use in php? i've been going through the manual, and the only thing i can find is strlen.

thanks in advance for your time!
-Ken

angst
04-07-2006, 10:15 PM
oh, i found it.
rtrim, ltrim should do what i need.

StupidRalph
04-08-2006, 01:25 PM
There isn't a Left nor Right function in PHP but they are easy to make using substr()


function left($string,$count) {
$string = substr($string,0,$count);
return $string;
}

function right($string,$count) {
$string = substr($string, -$count, $count);
return $string;
}

Now I haven't tested these but I'm pretty sure this is how you write them give them a try.
I forgot a semi-colon

degsy
04-10-2006, 03:55 PM
oh, i found it.
rtrim, ltrim should do what i need.
trim() would do both of them
http://uk2.php.net/trim

Also check the left menu onn that page. It gives you all the string functions



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum