placeholder in an article

2 posts by 2 authors in: Forums > CMS Builder
Last Post: November 6, 2020   (RSS)

By Dave - November 6, 2020

Hi petrogus, 

You could try something like this:

$str = "Hello #location# today is #weekday#!";
$str = replacePlaceholders($str);
print $str;
exit;

function replacePlaceholders($text) {

  $placeholders = [];
  $placeholders['location'] = "World"; 
  $placeholders['weekday']  = "Friday";
  
  foreach ($placeholders as $key => $value) {
    $text = str_replace("#$key#", $value, $text);
  }

  return $text;
}

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com