At this point I'm not inclined to do any kind of string replacement along these lines. My choice at present is to simply escape the \n~\n string should it be injected into a multi-line data variable.
Cheers, Dan On Mon, Jan 4, 2010 at 2:18 PM, DrunkenMonk <[email protected]> wrote: > >> I'd favor the simplest replacment of "\\" -> "\\\\" and "\n" -> "\\n", >> and vise versa. It would be the most human readable encoding method >> concerning that someone might directly modify the source code. However >> it could still cause a little backward compatibility problem if the >> data contains backslashes or breaklines. > > I'm less drunk now, and once again this replacement seems wrong to me, > if you use a simple str_replace(array, array). Consider: > > $a = "\\n"; > $from = array("\\", "\n"); > $to = array("\\\\", "\\n"); > > // forward conversion > $b = str_replace($from, $to, $a); > // backwards conversion > $c = str_replace($to, $from, $b); > > $c will becomes "\n", not "\\n". > > The reason, of course, is that str_replace does not respect escaped > characters. It is simpler to escape \ characters by appending a dummy > character than using a full fledged parser to perform a simple string- > replace. > > -- > > You received this message because you are subscribed to the Google Groups > "BoltWire" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/boltwire?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "BoltWire" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/boltwire?hl=en.
