I want users to represent a special variable say someone’s name by something like the string {name} in their text area submission, how do I now parse that textarea input with PHP or JS to convert {name} back to an actual name and not use {name} literally?
Advertisement
Answer
You can use str_replace
to replace all occurrence of {name}
. i.e.
<?php $string = "someone's name by something like the string {name} in their text area submission, how do I now parse that textarea input with PHP or JS to convert {name} back to an actual name and not use {name} literally?"; $replaced = str_replace('{name}', 'MR.real name', $string); echo $replaced; ?>