0

I'm planning to store a bunch of user-submitted TeX equations in a database. Problem is, TeX has stuff like \right... and PHP likes to consider \r as a newline character.

Is there any way to suppress this behaviour? I've tried addslashes and preg_replaceing the \r with \\r, but neither have worked out.

Edit: An example of stuff I'm expecting to get:

\[\left( {\begin{array}{*{20}{c}}
  {{a_{11}}}&{{a_{12}}} \\ 
  {{a_{21}}}&{{a_{22}}} 
\end{array}} \right)\]
Kyle
  • 4,205
  • 1
  • 21
  • 22

1 Answers1

2

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:

  1. Let it be a really user submitted data, not hardcoded in your PHP file.
  2. When put into SQL query, the data have to be properly formatted for this. Consult your database manual for the details.
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • Ok... trying I'm trying to print() the TeX chunk and getting `\[\left( {\begin{array}{*{20}{c}} {{a_{11}}}&{{a_{12}}} \ {{a_{21}}}&{{a_{22}}} \end{array}} ight)\]` - The \r in \right is missing. I'm missing something here... – Kyle Dec 21 '12 at 05:34
  • Piping it into json_encode and futzing around with preg_replace got it to work. Thanks for answering! – Kyle Dec 21 '12 at 05:45