5 Replies - 1882 Views - Last Post: 18 April 2011 - 01:01 AM

#1 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

PHP left() and right()

Posted 07 August 2008 - 11:22 PM

Description: Add functions to top of code, then call them using the following syntax: PHPs version of the ASP functions left() and right()



Is This A Good Question/Topic? 0
  • +

Replies To: PHP left() and right()

#2 Master Jake  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 108
  • Joined: 27-February 09

Re: PHP left() and right()

Posted 25 October 2009 - 10:23 AM

Actually, you can just use substr($string, -1) to return to rightmost character in a string. Replace -1 with how many characters from the right you want to return, of course.
Was This Post Helpful? 0
  • +
  • -

#3 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: PHP left() and right()

Posted 26 October 2009 - 12:20 AM

Thanks for the heads up Master Jake, I was unaware it supported negative values. I've updated the snippet to support your recommendations and in turn have a faster execution time.
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3722
  • View blog
  • Posts: 13,513
  • Joined: 08-August 08

Re: PHP left() and right()

Posted 05 June 2010 - 05:16 PM

I'm a little late here, but this looks redundant to me. Why wrap a function around an existing function?
substr($value, ($count*-1));
and
substr($string, 0, $count);
are really all you need.
Was This Post Helpful? 0
  • +
  • -

#5 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: PHP left() and right()

Posted 26 September 2010 - 11:40 PM

Hi CTphpnwb, it's a simple transition function for classic ASP developers to 'pick up and run' with PHP. I agree entirely though - I wouldn't drop those functions into a PHP project, however it would of saved me a lot of head scratching when i first moved from ASP to PHP.
Was This Post Helpful? 0
  • +
  • -

#6 radjab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 25-March 11

Re: PHP left() and right()

Posted 18 April 2011 - 01:01 AM

how to run a php program using xampp?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1