Pregunta

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)\]
¿Fue útil?

Solución

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.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top