I am using the php imap libaray's imap_search() function to search mails in gmail inbox via subject string.
imap_seach($mbox, 'ALL SUBJECT "<search string>"');
This search returns perfectly fine for alphanumeric strings but fails when it has special characters like slash, comma, colon, single quote, hyphen, colon and many other characters that I do not even know of. Escaping them doesn't help. Replacing a few of them with space helps sometime but not in all cases.
Is there a standard way to filter the search string so that it never errors out and returns some result? I have tried tokenizing the subject sting and removing all words from the search string which even one alphanumeric characters. This mostly works but fails when all the words have non-alphanumeric character (which is common for single or two word subject).
thanks