Answers for "replace the first character in a string in php"

PHP
0

php substr_replace

<?php
$var = 'ABCDEFGH:/MNRPQR/';
echo "Original: $var<hr />n";

/* These two examples replace all of $var with 'bob'. */
echo substr_replace($var, 'bob', 0) . "<br />n";
echo substr_replace($var, 'bob', 0, strlen($var)) . "<br />n";

/* Insert 'bob' right at the beginning of $var. */
echo substr_replace($var, 'bob', 0, 0) . "<br />n";

/* These next two replace 'MNRPQR' in $var with 'bob'. */
echo substr_replace($var, 'bob', 10, -1) . "<br />n";
echo substr_replace($var, 'bob', -7, -1) . "<br />n";

/* Delete 'MNRPQR' from $var. */
echo substr_replace($var, '', 10, -1) . "<br />n";
?>
Posted by: Guest on November-19-2020

Code answers related to "replace the first character in a string in php"

Browse Popular Code Answers by Language