I've got strings that look like this: " edited profile picture of " - The numbers in brackets stand for ID's of users (saved in Database). What would be an efficient way to replace these numbers with data from the database in PHP? I should also mention, that there can be zero of these numbers as well as twenty of them in a string. Thanks in advance!
Use the function strtr
<?php $string = ' edited profile picture of '; $replaceArray = array('' => 'Mark Zuckerberg', '' => 'John doe'); $string = strtr($sting, $replaceArray); echo $string; ?>
Mark Zuckerberg edited profile picture of John doe