Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    LEFT/RIGHT for php?

    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

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    oh, i found it.
    rtrim, ltrim should do what i need.

  • #3
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    There isn't a Left nor Right function in PHP but they are easy to make using substr()
    PHP Code:
    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.
    Edit: I forgot a semi-colon
    Last edited by StupidRalph; 04-08-2006 at 12:32 PM.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by angst
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •