Escape individual quotes and the dollar sign in for ImageMagick in PHP

I have a command to convert imagemagick using subtitles like this:

convert -size 100x100 -caption: "& # 39 ;. $ mystring. & # 39;" 

I have two cases where I have problems passing the string to the conversion command:

The first has to do with dollar signs:

$ mystring = & # 39; $ 24.95 IS THE PRICE & # 39;

This would appear as: 4.95 IS THE PRICE after ImageMagick processed it.

Therefore, I used

quotemeta ($ mystring);

What worked well, but then I had this other problem in which there was only one appointment at the beginning of the chain:

$ mystring = & # 39; "The man went to the park and & # 39 ;;

This completely broke the script and ImageMagick gave an error when looking for another appointment to go with the first one.

I guess I need to know how to deal with all the different possible text combos that might appear and break this code and how to escape from them? What is the standard solution?