|
-
Jan 19th, 2003, 11:55 AM
#1
Thread Starter
New Member
how to check if a ";" is at the end of a string?
hi!
I have got a problem:
how can I check if a ";" is at the end of a string?
e.g.
$str = "This is a test;";
now I want the php script to check if at the end of $str is a ";" - if so, there should come an echo "found a ";" at the end"; !
perhaps you can help me, by saying how the function is called.
thanx a lot,
stylewriter
-
Jan 19th, 2003, 12:01 PM
#2
Stuck in the 80s
Code:
$str = "blah blah;";
if (substr($str, strlen($str) - 1, 1) == ";") {
echo "found ;!";
}
Should work.
-
Jan 19th, 2003, 12:19 PM
#3
Thread Starter
New Member
ok, thanx!
and how is it possible that the ";" at the end of the string will be deleted?
sry, but I don't know the names of the functions allready...
Last edited by Stylewriter; Jan 19th, 2003 at 01:02 PM.
-=|www.mechboxer.de|=-
-
Jan 19th, 2003, 01:10 PM
#4
Stuck in the 80s
Code:
$str = "blah blah;";
if (substr($str, strlen($str) - 1, 1) == ";") {
//if the ; exists, remove it:
$str = substr($str, 0, strlen($str) - 1);
}
echo $str; //output: blah blah
Function substr():
Syntax: substr (string string, int start [, int length])
Description: Substr returns the portion of string specified by the start and length parameters.
Example:
Code:
echo substr("12345", 1, 2);
//output: 23
Function strlen():
Syntax: strlen (string str)
Description: Returns the length of string.
Example:
Code:
echo strlen("1234");
//output: 4
Hope this helps.
-
Jan 19th, 2003, 01:39 PM
#5
Thread Starter
New Member
yes, it works!
thanx a lot for the detailed information!!!
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
|