I want to delete any dollar sign($) from a PHP variable only if it surrounds a word.
I know how to replace every $ with empty space to look like is deleted, for example:
<?php
$string = 'Hello $George$';
$string = str_replace('$', '', $string);
echo $string; // Prints: Hello George
?>
But the code above is also removing $ that are not surrounding a word, for example:
<?php
$string = 'Hello $George$, are you $ok?';
$string = str_replace('$', '', $string);
echo $string; // Prints Hello George, are you ok?
?>
I've been trying for many hours to solve this problem but didn't manage to puzzle it out, any help is appreciated.