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!
Answer: Use the PHP strpos() Function You can use the PHP strpos() function to check whether a string contains a specific word or not. The strpos() function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false .
Definition and Usage. The strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow parameter.
Using str_replace() Method: The str_replace() method is used to remove all the special characters from the given string str by replacing these characters with the white space (” “).
<?php $string = 'foo'; if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $string)) { // one or more of the 'special characters' found in $string }
preg_match('/'.preg_quote('^\'£$%^&*()}{@#~?><,@|-=-_+-¬', '/').'/', $string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With