note 85994 deleted from function.substr by felipe

From: Date: Sun, 28 Sep 2008 01:09:33 +0000
Subject: note 85994 deleted from function.substr by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-144847@lists.php.net to get a copy of this message
Note Submitter: Elliot at notwothesame dot com ---- Your function doesn't quite work as expected. If you want to insert something, say 20 characters from the end it works, but not 20 characters from the beginning. Slight tweak: function insert_substr($str, $pos, $substr) { $pos = strlen($str) - $pos; $part1 = substr($str, 0, -$pos); $part2 = substr($str, -$pos); return $part1.$substr.$part2; } $str = "12345678901234567890123456789"; echo insert_substr($str, 20, "<br />"); Output: "12345678901234567890<br />123456789"

« previous php.notes (#144847) next »