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

python - Writing Greek in matplotlib labels, titles -

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -