Q:

I want to replace all instances of {0} on a page with an image or run a function when that is printed out. can i do this with php?

I am making a widget that shows images in places where the user puts a {0} or {5}. can this be done with php? i dont know where to start and i have worn out my fingertips searching for it on google because i dont know good keywords.

A:

Yes, it can be done. For simple cases use str_replacedocs and for more complex cases use preg_replacedocs.
The supplied PHP manual links will tell you all about it. You'll probably want to try str_replace first as it's much simpler than using regular expressions.
// replace all occurrences of "{0}" with "AWESOME"
$str = "{0} --- {0}";
$str = str_replace("{0}", "AWESOME", $str);
echo $str; // outputs: AWESOME --- AWESOME

