Sbm007
2009-09-26 14:09:10
ok, but if i change that in file 1 (which is the one that isn't working) then i won't be getting the desired effect in either?
Neil Hickman
2009-09-26 20:05:18
Well do the opposite in file 1 then, replace $copy = preg_replace('^(.*)\n(.*)^', '$1<br />$2', $js_r->copy); $copy = preg_replace('/[\r]+/', '$1<br />$2', $copy); with $copy = preg_replace('/[\r]+/', '$1<br />$2', $js_r->copy);I apologize for the lack of code formatting in comments.
Sbm007
2009-09-26 20:10:59
it could work, but then as in another question i had that originally we came to the conclusion that the parsing of \n is required, otherwise it will break my javascript that i have. i'm out the office at the moment so when i get back i'll try it and let you know.
Neil Hickman
2009-09-26 21:36:45
Yeah I found that quite odd in your code, you could just simply do a $code = str_replace("\n", "<br />", $js_r->copy); That's 2 lines in 1 and better performance. Not entirely sure why you decided to use regular expressions for this, as that is overkill.
Sbm007
2009-09-26 22:41:16
as i imagined, that has now broken the first file as in the same problem i had with the original question
Neil Hickman
2009-09-27 19:24:08
A:
Ok,
So it seems it was the parsing of the line breaks in the file... However we have changed it from
as this is causing the issue of the markdown parsing incorrectly to double escaped
so it now reads
$copy = preg_replace("/\n/", "\\\\n", $js_r->copy);
$copy = preg_replace("/\r/", "\\\\r", $copy);
which works correctly and parses both files efficiently
Neil Hickman
2009-09-27 21:06:45
Ok, glad it worked out well. By the way you may want to consider using str_replace instead of preg_replace as it is much faster (non regex).
Sbm007
2009-09-27 21:16:07
i did take up your advise after i posted that ... i'm all for saving resources... thanks for pointing me in the right direction anyway!
Neil Hickman
2009-09-27 23:43:16