DekGenius.com
PHP
php str_replace
<?php
//str_replace("Original Value", "Value to be replaced", "String");
$result = str_replace("1", "2", "This is number 1");
// Output: This is number 2
?>
str_replace php variable
$var1 = 'hello.world';
$var2 = str_replace(".", "-", $var1);
echo $var2; // hello-world
str_replace php
echo str_replace("worss","world","Hello worss in PHP!!");
php replace string within string
$new_string = str_replace( $take_out, $put_in, $string);
str_replace php variable
$var1 = 'hello_john';
$var2 = str_replace("_", "-", $var1);
echo $var2; // hello-john
replace in php
# for replace someting in string use this function
# str_replace("1st param for select","2nd param for replace with","3rd your string")
<?php
$string = str_replace(" ", "_", "Hello World");
// Output will be : Hello_world
?>
replace text in string php
echo str_replace("Initial Value", "Replace with", "This is the Initial value");
replace exact word in php
$string = preg_replace('/the/', '', $string);
php str replace
<?php
$string = str_ireplace("FoX", "CAT", "the quick brown fox jumps over the lazy dog");
echo $string; // the quick brown CAT jumps over the lazy dog
?>
Replace Word In String PHP
<?php
echo str_replace(“red”, “blue”, “red carpet”);
?>
php str_replace
<?php
// Produce: Hll Wrld f PHP
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
?>
php substr_replace
<?php
$var = 'ABCDEFGH:/MNRPQR/';
echo "Original: $var<hr />
";
/* These two examples replace all of $var with 'bob'. */
echo substr_replace($var, 'bob', 0) . "<br />
";
echo substr_replace($var, 'bob', 0, strlen($var)) . "<br />
";
/* Insert 'bob' right at the beginning of $var. */
echo substr_replace($var, 'bob', 0, 0) . "<br />
";
/* These next two replace 'MNRPQR' in $var with 'bob'. */
echo substr_replace($var, 'bob', 10, -1) . "<br />
";
echo substr_replace($var, 'bob', -7, -1) . "<br />
";
/* Delete 'MNRPQR' from $var. */
echo substr_replace($var, '', 10, -1) . "<br />
";
?>
PHP substr_replace — Replace text within a portion of a string
<?php
$var = 'ABCDEFGH:/MNRPQR/';
echo "Original: $var<hr />
";
/* These two examples replace all of $var with 'bob'. */
echo substr_replace($var, 'bob', 0) . "<br />
";
echo substr_replace($var, 'bob', 0, strlen($var)) . "<br />
";
/* Insert 'bob' right at the beginning of $var. */
echo substr_replace($var, 'bob', 0, 0) . "<br />
";
/* These next two replace 'MNRPQR' in $var with 'bob'. */
echo substr_replace($var, 'bob', 10, -1) . "<br />
";
echo substr_replace($var, 'bob', -7, -1) . "<br />
";
/* Delete 'MNRPQR' from $var. */
echo substr_replace($var, '', 10, -1) . "<br />
";
?>
string replace in php
© 2022 Copyright:
DekGenius.com