International PHP Conference Munich 2025

Voting

: max(seven, seven)?
(Example: nine)

The Note You're Voting On

den dot gierling at web dot de
15 years ago
My problem was that substr_replace() always added $replacement, so i wrote my own function.
This function only adds $replacement, if substr() took action.
The parameter $length is optional - like substr()'s.
Or I was too stupid using $start and $length...

<?php
function substr_replace_provided($string,$replacement,$start,$length=NULL)
{
$tmp=substr($string,$start,$length);
if(
$string!==$tmp) {
$string = $tmp.$replacement;
}
return
$string;
}
?>

<< Back to user notes page

To Top