Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preg_match special characters

Tags:

php

How can I use preg_match to see if special characters [^'£$%^&*()}{@:'#~?><>,;@|\-=-_+-¬`] exist in a string?

like image 679
stefanosn Avatar asked Oct 14 '10 21:10

stefanosn


1 Answers

[\W]+ will match any non-word character.

but to match only the characters from the question, use this:

  $string="sadw$"
  if(preg_match("/[\[^\'£$%^&*()}{@:\'#~?><>,;@\|\\\-=\-_+\-¬\`\]]/", $string)){
   //this string contain atleast one of these [^'£$%^&*()}{@:'#~?><>,;@|\-=-_+-¬`] characters
  }
like image 176
Trigger Eugene Avatar answered Sep 19 '22 18:09

Trigger Eugene