I was looking for a way in php which can replace a string like this
<?php
$ar = array(
"ToFind" => "ToBeReplaced",
"ToFind1" => "ToBeReplaced1"
);
?>
and so on ?
Any help ?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simple replacement tasks can be done like this using
str_replace:As noted in the examples, this may sometimes lead to unexpected behaviour because the replacement is performed left-to-right, ie. the output of the first replacement acts as input for the second replacement and so on. The comments on the PHP manual page for
str_replacecontain a lot of ideas for replacing occurrences in the original string. This one, for example, might be close to what you’re looking for: