Basically, I want to use both $city_name
and $ref_name
with str_replace(), so that if either one (or both) of them are inputted by the user, both of them are replaced with their actual variable forms.
To give a better illustration, here's m开发者_Go百科y current code;
$headlines = array('primary_headline' => $_POST['primary_headline'], 'secondary_headline' => $_POST['secondary_headline'], 'primary_subline' => $_POST['primary_subline'], 'secondary_subtext' => $_POST['secondary_subtext']);
$city_name = "Dallas";
$ref_name = "Facebook";
if(isset($headlines)) {
foreach($headlines as $headline) {
echo(str_replace('$city_name', $city_name, $headline));
}
}
I'd basically like str_replace('$city_name', $city_name, $headline)
to become str_replace('$city_name' AND/OR '$ref_name', $city_name AND/OR $ref_name, $headline)
.
Any answers or comments will be greatly appreciated!
http://php.net/manual/en/function.str-replace.php
$searches = array('$city_name', '$ref_name');
$replacements = array($city_name, $ref_name);
echo str_replace($searches, $replacements, $headline);
精彩评论