note 13344 deleted from function.chop by irc-html

From: Date: Wed, 16 Jan 2002 16:21:03 +0000
Subject: note 13344 deleted from function.chop by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-24907@lists.php.net to get a copy of this message
perl chop in php: $return_char = perl_chop($var); function perl_chop(&$var) { $char = substr($var, -1); $var = substr($var, 0, -1); } perl-chomp (which chops off the last char only if it is a \n (actually, whatever the value of $/ is, which is non-existant in php)): $return_char = perl_chomp($var [, chomp char]); function perl_chomp(&$var, $char = "\n") { if(substr($var, (0 - strlen($char))) == $char) { $var = substr($var, 0, (0 - strlen($char))); return $char; } } These function would work exactly the same in php as they do in perl now. (though perl_chomp() has an optional 2nd param to specify what char to lop off... this can be any lenght... like 'asdf', and it would lop that off): $var = 'test'; print perl_chop($var); // would print 't' and $var would now equal 'tes' $var = 'teststring'; print perl_chomp($var, 'string'); // would print 'string' and $var would equal 'test'

« previous php.notes (#24907) next »