I come to think of several solutions; basically you would want your php-page to parse the data and create a trusted output that can be printed (i.e. a PDF-file, if your printer supports this).
Your next task is how to have this trusted output sent to the printer. Again, several solutions exists.
Have your php-script execute a system executable, e.g. cat output.pdf > /dev/ttyxxx (it is clear here, that I do not know how to print from unix). Notice that the executable is not dependent on input at all, i.e. you want to reduce the risk of injection attacks and the like. This point requires that the output.pdf, that you created, is trustworthy.
Have a cron-job look for output files and send them to the printer. Same considerations as above apply. This might be better as it can avoid bottlenecks if multiple php-sessions are trying to print a document.
Build a smaller framework around the above that can report back if errors occur etc. But still, basically option 1 + magic.
All in all, split the process into two steps. One that accepts the input, parses and checks for erroneousness/malevolent input, and creates the needed output for the printer. This can be done in a protected environment, which if hacked, does not expose the system (at least not more than the usual php would).
Step 2 then takes care of sending the output to the hardware, either bash-script, executable, or python.