0

Hi i want to find if string content this "|" this character.

example:-

$string = '$18,000 | new price'; 

if (preg_match('/[^|]/', $string)) {

}
else {

}

2 Answers2

2

The pattern is wrong. No need of ^ in this case. Should be -

preg_match('/[|]/', $string);

You can use storpos -

$string = '$18,000 | new price';
if(strpos($string, '|')) { ... }
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
1

This should do the work.

$string = '$18,000 | new price'; 

if (strpos($string , '|') === false) {
     // Not found.
}
else {
    // Found.
}

http://php.net/strpos

Umair Khan
  • 1,684
  • 18
  • 34