Answers for "php substr_replace on array of strings"

PHP
0

php replace string with array values

$string = "last_name, first_name";
$search = array('first_name', 'last_name');
$replace = array('John', 'Smith');

$result = str_replace($search, $replace, $string);
Posted by: Guest on June-15-2021
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 "php substr_replace on array of strings"

Browse Popular Code Answers by Language