PHP likes to consider \r as a newline character.
Nope, PHP doesn't.
Just store these equations in a database usual way, there should be no problem.
You just need to follow 2 rules:
- Let it be a really user submitted data, not hardcoded in your PHP file.
- When put into SQL query, the data have to be properly formatted for this. Consult your database manual for the details.