|
-
Nov 22nd, 2005, 11:41 PM
#1
Thread Starter
Admodistrator
Cut off last char of a string
PHP Code:
$str = substr($str,strlen($str)-1);
i thought that would take my string, and take the last char off, how do i do it?
Also, is the newline character "\n" because it isnt working correctly..
Last edited by |2eM!x; Nov 23rd, 2005 at 01:44 AM.
-
Nov 23rd, 2005, 08:15 AM
#2
Re: Cut off last char of a string
In windows the newline consists of two characters \r\n and in MAC OS the newline character is just a carrige return \r. To shaveo ff the last n chracters:
PHP Code:
$str = substr($str, -1);
-
Nov 23rd, 2005, 09:26 AM
#3
Re: Cut off last char of a string
But if you're just looking to get rid of trailing whitespace, trim() would be a better choice.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 23rd, 2005, 12:31 PM
#4
Thread Starter
Admodistrator
Re: Cut off last char of a string
Thanks guys, i resolved this myself:
PHP Code:
$ip = substr($ip,0,-1);
vAd, that just left me with the last char, it didnt cut it off of the string (well actually i guess it did..)
CornedBee, it isnt the same thing every time, and it is not whitespace ever, thanks though
-
Nov 24th, 2005, 01:03 AM
#5
Re: Cut off last char of a string
oops
-
Nov 24th, 2005, 12:17 PM
#6
Thread Starter
Admodistrator
Re: Cut off last char of a string
Thanks anyways, i should type clearer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|