note 114553 added to function.substr-replace
| From: | ivijan dot stefan at gmail dot com | Date: | Wed, 05 Mar 2014 20:15:48 +0000 |
| Subject: | note 114553 added to function.substr-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198805@lists.php.net to get a copy of this message | ||
I have a little function that works like substr_replace () what I use for some purpose. Maybe
someone needs it.
<?php
function putinplace($string=NULL, $put=NULL, $position=false)
{
$d1=$d2=$i=false;
$d=array(strlen($string), strlen($put));
if($position > $d[0]) $position=$d[0];
for($i=$d[0]; $i >= $position; $i--) $string[$i+$d[1]]=$string[$i];
for($i=0; $i<$d[1]; $i++) $string[$position+$i]=$put[$i];
return $string;
}
// Explanation
$string='My dog dont love postman'; // string
$put="'"; // put ' on position
$position=10; // number of characters (position)
print_r( putinplace($string, $put, $position) );
?>
RESULT: My dog don't love postman
This is a small powerful function that performs its job flawlessly.
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.substr-replace.php
Edit -- https://master.php.net/note/edit/114553
Del: integrated -- https://master.php.net/note/delete/114553/integrated
Del: useless -- https://master.php.net/note/delete/114553/useless
Del: bad code -- https://master.php.net/note/delete/114553/bad+code
Del: spam -- https://master.php.net/note/delete/114553/spam
Del: non-english -- https://master.php.net/note/delete/114553/non-english
Del: in docs -- https://master.php.net/note/delete/114553/in+docs
Del: other reasons-- https://master.php.net/note/delete/114553
Reject -- https://master.php.net/note/reject/114553
Search -- https://master.php.net/manage/user-notes.php