Find the occurrence of backslash in a string
If my string is : aud\ios , how do i check it out for the presence of \ in it? I tried using preg_match('\\' , $string) but it does not work. What's the correct way to achieve this? Amal Murali For something simple as this, you don't need a regular expression. A string function like strpos() should be enough: if (strpos('aud\ios', '\\') !== FALSE) { // String contains '\' } Note that you need to escape the backslash here. If you simply write \ , then PHP considers it as an escape sequence and tries to escape the character that follows. To avoid this, you need to escape the escape using another