1

In a textarea of an html form I allow multi line inputs such as:


hello

goodbye


This string is then put into a mysql database with mysql_real_escape_string. Now I want to take this string and pass it directly into a tex document, but the empty lines (carriage returns I suppose) are not being output with the string. Hence when this is compiled with latex I get the output


hellornrngoodbye


What do I need to do to my string to retain the carriage returns?

1 Answer 1

2

After our discussion in chat, here's what we figured out:

You used

shell_exec("cat ".$PATH."/LatexTemplate.tex | sed -e 's/LatexCode/$latexcode/' > ".$PATH."/TexFiles/Q$id.tex");

inside a PHP script to insert the latex input stored in the DB into a template file and save that. Somewhere in this process, the newlines got dropped.

The best solution would be to replace the shell exec with a PHP equivalent that loads the file into a string, performs a string replacement with the (unescaped) input string and stores it in another file.

Sign up to request clarification or add additional context in comments.

6 Comments

I did try this: $str = str_replace('\r\n','\\',$str); but all I got was this inserted into my tex file: hello\goodbye. Which isn't correct.
Geoff: That's because you are doing the replace in a language which uses `\` as an escape character. See my edit :)
Yes, I tried this too, and in this case it works! BUT Let's say I want to continue with \begin{enumerate} (CR) \item hi (CR) \end{enumerate}, then I get \\ in my tex file before the \item and then that doesn't work. So ideally I would like really an empty space/carriage return parsed into the tex source rather than simulating it with \\.
ps: how can I do line breaks in the comments? I hit enter, and the comment is posted!
@Geoff: I don't follow. Can you edit the original question to include this example?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.