I have a string like, "[one]sdasf[two]sad[three]"
So, I want to replace [one] with "replaced_one"
, [two] with "replaced_two"
.
and I need those replaced values as separate strings.
$rep_one = "replaced_one";
$rep_two = "replaced_two";
I have a string like, "[one]sdasf[two]sad[three]"
So, I want to replace [one] with "replaced_one"
, [two] with "replaced_two"
.
and I need those replaced values as separate strings.
$rep_one = "replaced_one";
$rep_two = "replaced_two";
This is a simple PHP function str_replace()
(For more info go to PHP Manual)
The function is expecting three parameters:
str_replace(
# Search - string section to be replaced
# Replace - the content which will replace the `Search`
# Subject - The string you want to alter
)
So in your case you can simply do this:
$str = "[one]sdasf[two]sad[three]";
$str = str_replace('[one]', 'replace_one', $str);
$str = str_replace('[two]', 'replace_two', $str);
echo $str; // replace_onesdasfreplace_twosad[three]