Tomas Salazar Tomas Salazar - 1 year ago 98
PHP Question

Consider certain string as variable

my php script gets a json config file. In this case, $json->autowelcome is "Hello {user}, welcome!"

I want php to interpreter the {user} as $user. How can i do that?

// Answer to tickle every 5 seconds
if (time() - dataAPI::get($key) >= 5) {
dataAPI::set($key, time());
$name = $bot->users[$who]->getRegname();
$bot->network->sendMessageAutoDetection($who, $bot->botData['ontickle'], 2,true);


Answer Source

I can suggest you to use str_replace. Easier way.


$string   = 'Hello {name}!';
$search[] = '{id}';            $replace[] = $user->getID();
$search[] = '{name}';          $replace[] = $user->getNick();
$search[] = '{regname}';       $replace[] = $user->getRegname();
return str_replace($search, $replace, $string);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download