Welcome to Maxi-Pedia Forum. Maxi-Pedia discussion forum is a free community inviting you to express your ideas and discuss various topics with other contributors.

April 19, 2024, 12:17:06 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Most Recent Posts:
Pages: [1]
  Print  
Author
Topic: 

Left, right function in PHP?

 (Read 121344 times)
danisara
Sr. Member
****
Posts: 280


« 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
Logged
Maxi-Pedia Forum
« on: November 19, 2008, 09:56:35 pm »

 Logged
atari
Full Member
***
Posts: 121


« Reply #1 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!
Logged
aliatwa2020
Semi-Newbie
*
Posts: 6


« Reply #2 on: January 18, 2011, 01:08:01 am »

I am not sure, but I think one approach also could be to use regular expressions.
« Last Edit: January 18, 2011, 12:55:58 pm by aliatwa2020 » Logged
Maxi-Pedia Forum
   

 Logged
Pages: [1]
  Print  
 
Jump to:  

Page created in 0.06 seconds with 22 queries. (Pretty URLs adds 0s, 0q)