32

Possible Duplicate:
preg_match php special characters

Hi all, I want to check if these characters exist in a string by using preg_match:

^'£$%^&*()}{@'#~?><>,@|\-=-_+-¬'

Help please!

SharpC
  • 6,974
  • 4
  • 45
  • 40
stefanosn
  • 3,264
  • 10
  • 53
  • 79

2 Answers2

87
<?php

$string = 'foo';

if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $string))
{
    // one or more of the 'special characters' found in $string
}
chigley
  • 2,562
  • 20
  • 18
10

preg_match('/'.preg_quote('^\'£$%^&*()}{@#~?><,@|-=-_+-¬', '/').'/', $string);

Petah
  • 45,477
  • 28
  • 157
  • 213
  • 1
    Didn't realize that `preg_quote` was an available function. May be useful to some. – Chad Feb 27 '19 at 16:59