php - preg_replace() escaping: single vs double backslash? -


I have seen preg_replace () with double backslash to prevent someone (e.g., < Code> instead of & nbsp; ).

Is it necessary? I tried both ways and I do not know what is

preg_replace ('/ / lt; div & gt; \\ s * text & Lt; \\ / div & gt; / ',' ', $ Somestring);

', $ a backslash in PHP string literally ;

For a typical meaning, for example, "\ n" is a new row, not a string "\ n". "To write the string" \ n ", you must type the code " \\ n " However, if there is no special meaning after the backslash, then the backslash is taken as such "\ foo" is required to be saved as . The ring "\ foo" is the only case in single-quoted wires in which you need to avoid backslash, which is directly before the end of the string: 'foo' \\ ' รข? ??? "Foo \".

Therefore, writing the \\ / in PHP code string or \ / The meaning is the same, because / is of no special importance to PHP, is correct in any way, it is not about Reges syntax but it is about PHP syntax.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -