PHP Newsletter

Join now and receive weekly updates pertianing to the world of PHP.

Polls

What do you think about the new PHPMine Design?
Awesome
Not Bad
Sucks

PHP Gigs By City

PHP Jobs By Topic

Advertisements

PHP Delete last character if dot?

Asked 2010-03-08 16:12:41 by Cthulhu

Hello. I have this code:
$labels = explode(",", $_POST['labels']);
foreach($labels as $val) {
$val = trim($val);
mysql_query("INSERT INTO TABLENAME (name, cat_id) VALUES ('".mysql_real_escape_string($val)."', '$cat')");
}
As you understood it user's labels function. Every label inserted separately (separated by comma).
I want to check if last character in the input form of labels is dot- so user means that this is the end of his list of labels. So how do i check in such construction the last character and if it's a dot - remove?
already tried substr...doesn't work

Anwered 2010-03-08 16:18:13 by Colanth

substr($yourstring, -1) is the last character of the string.

Questions and answers provided by the Yahoo Answers Community.