note 79107 deleted from function.substr by tularis

From: Date: Mon, 31 Dec 2007 10:45:57 +0000
Subject: note 79107 deleted from function.substr by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134604@lists.php.net to get a copy of this message
Note Submitter: kevin at lux-fiat dot com ---- If the last character you want to trim from a string is an escape char like "\n", make sure you only strip 1 char, not 2. I discovered this when my code building some javascript chopped off the final paren when I used $mainmenu = substr($mainmenu, 0, -2); instead of $mainmenu = substr($mainmenu, 0, -1); <?php $mainmenu = ''; foreach($menu as $value) { $pname = $value['pagename']; $parent = $value['parent']; $title = $value['menutitle']; $href = $pname . '.php'; switch ($parent) { case '': case 'index': $mainmenu .= "mymenu.addMenu(\"$pname\",\"<b>$title</b>\", \"$href\")\n"; break; default: $submenu .= "mymenu.addSubMenu(\"$parent\", \"$pname\", \"<b>$title</b>\", \"$href\")\n"; } } $mainmenu = substr($mainmenu, 0, -1); $submenu = substr($submenu, 0, -1); ?>

« previous php.notes (#134604) next »