Maxi-Pedia Forum

Information Technologies and Systems (IT/IS) => Other, SEO: Feel free to build your links here => Topic started by: danisara on November 19, 2008, 09:56:35 pm



Title: Left, right function in PHP?
Post by: danisara on November 19, 2008, 09:56:35 pm
In VB and in Excel functions, there is function called left() and right() which returns a part of a string either from left or right. Is there something like this in PHP? I can't find anything that would do the same in PHP. Plz, help. Tx


Title: Re: Left, right function in PHP?
Post by: atari on November 20, 2008, 11:21:19 am
In VB and in Excel functions, there is function called left() and right() which returns a part of a string either from left or right. Is there something like this in PHP? I can't find anything that would do the same in PHP. Plz, help. Tx



Here you go, my friend,

Code:
function left($str, $length) {
     return substr($str, 0, $length);
}

function right($str, $length) {
     return substr($str, -$length);
}

echo left("Hello World", 5); // Hello
echo right("Hello World", 5); // World

Cheers!


Title: Re: Left, right function in PHP?
Post by: aliatwa2020 on January 18, 2011, 01:08:01 am
I am not sure, but I think one approach also could be to use regular expressions.