CakeFest 2025 Madrid: The Official CakePHP Conference

Voting

: six plus two?
(Example: nine)

The Note You're Voting On

ivijan dot stefan at gmail dot com
11 years ago
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.

<< Back to user notes page

To Top