Hi,
I have a $var which contains a set of characters. I want to check that another string, $string, ONLY contains characters contained within $var.
Is there any PHP string function that does this?
Many thanks.
Checking for characters in a string
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
You will need to play with the logic, but maybe something like this:
That is checking to see if a character not in the set of characters is not found ... hard to follow the double negative though.
Code: Select all
if (preg_match("[^$var]", $string) == 0) {(#10850)
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
You should probably pass $var through preg_quote() as well.