It is more complex than that.
You could probably pull it off using the functions:
preg_match();
to find the php references and save them into an array.
and then:
eval()
to execute the php code and get the result
Then finally str_replace() to replace it.
It is worth noting that you will want to disable inline editing with either technique (yours or the more complex one) since any dynamic values would end up being replaced with their values as soon as the inline edits were saved.
I have gotten around this limitation to allow any dynamic value, but the solution becomes pretty complex. It involves using code like this for the placeholder:
<span class="php_replace" rel="$variablename">sample value</span>
Then I search through the code for anything with the "php_replace" class using preg_match() and when I replace it I only update the "sample value" portion and leave the rest of the tag intact. This way you can still use the inline editor, but if you replace the dynamic portion your edits are ignored and the value stays dynamic since you wouldn't ever actually remove the <span> and its class while editing.