# PHP Puzzlement

Did the meaning of the character sequence \f in PHP change overnight? I just had a bizarre error in my LaTeX rendering plugin, which I ended up fixing by adding a whole bunch of extra backslashes. LaTeXrender works by generating a LaTeX document from a formula in a webpage and then passing that document through the LaTeX interpreter, converting the output into an image which is placed in the webpage. This means that the peculiarities of LaTeX and of PHP must both be respected, and because both languages use the backslash character for special purposes, extra backslashes appear when those purposes collide.

For example, \n in PHP (and in C) stands for a newline character (yes, we are still slave to the teletype). So, if you want your PHP program to output a character string containing the LaTeX command \newline, you have to write \\newline. The first backslash “escapes” the second.

Suddenly, LaTeXrender started spewing out garbage: big blocks of image with bits of LaTeX commands inside, wrapped around a formula in the middle. Something must have started going wrong with the text being passed to LaTeX. How did I, the seasoned LaTeX guru and MIT graduate, solve this conundrum?

I threw backslashes at the problem until it went away.

No, seriously: all LaTeX commands starting with \f, like \formulabox or whatever, needed an extra backslash. I changed every instance of \f in the PHP source code to \\f, and now the plugin works again. Why this is necessary today but wasn’t necessary yesterday. . . I leave that as an exercise for the interested reader.

This is why I don’t have a nice post about the Dirac Equation for you today.

## 4 thoughts on “PHP Puzzlement”

1. gg says:

“This is why I donâ€™t have a nice post about the Dirac Equation for you today.”

Oh, admit it: you accidentally found proof that relativity and quantum mechanics are completely wrong and don’t want to admit it! It’s a conspiracy, I tell you!

(Damn, I must be reading too many crackpots these days… can’t… get… their conspiracies out… of my head!) :)

2. “Why this is necessary today but wasnâ€™t necessary yesterday. . .”

I’m guessing there was an upgrade to provide better teletype form feed compatibility ;-)

3. The algorithm says:

Hah, you may have looked this up and been asking “why” in a more philosophical sense, but \f behavior actually did change in the very last update to PHP: docs say it was added in 5.2.5, which is the latest version available to download. So maybe something cleverly decided to update your PHP from whatever was in stock Debian on the new server. Pretty impressive, in a not-great way, that PHP introduced a backwards-incompatible change in a minor update like that. (Or if the docs were wrong about when the \f change happened, that’s impressive too.)

4. M\$ Visual PHP anyone…