2

I am trying to see if the string contains \ and if i put it like this

$search4 = '\'; or like $search4 = "\"; it won't work as this is incorrect.

This is my search function

function Search($search, $string){
$position = strpos($string, $search);
if ($position == true){
    return 'true';
}
else{
    return 'false';
}}

And i am calling it like that echo Search($search4, $string);

1 Answers1

2

You need to escape the \ by using 2 \. Because '\' is escaping the single quote and is giving you an error. The same will happend with double quotes.

http://php.net/manual/en/regexp.reference.escape.php

function Search($search, $string){
    $position = strpos($string, $search);
    if ($position == true){
        return 'true';
    }else{
        return 'false';
    }
}

$search = '\\';
print Search($search, "someString");
Vidal
  • 2,605
  • 2
  • 16
  • 32