Thursday, April 20, 2017

str_replace

<?php
$value = "abc def";
echo "\$value is " . $value . "<br/>";
$replace_a_with_x = str_replace("a", "x", $value);
echo "\$replace_a_with_x is: " . $replace_a_with_x . "<br/>";
$replace_array_of_char_with_num = str_replace(array("a", "b", "c"), 1, $value);
echo "\$replace_array_of_char_with_num is: " . $replace_array_of_char_with_num . "<br/>";
$replace_array_of_char_with_num_array = str_replace(array("a", "b", "c"), array(1, 2, 3), $value);
echo "\$replace_array_of_char_with_num_array is: " . $replace_array_of_char_with_num_array . "<br/>";
?>
Output:
$value is abc def
$replace_a_with_x is: xbc def
$replace_array_of_char_with_num is: 111 def
$replace_array_of_char_with_num_array is: 123 def

No comments:

Post a Comment

here docs

$x = <<<THE_END PHP stands for "PHP: Hypertext Preprocessor". The acronym "PHP" is therefore, usually referre...