Could someone help me create something that checks if a string contains any of these characters,
\/:*?"<>|
Just point me in the right direction, thanks (I'm guessing preg?)
Check if text contains...
Re: Check if text contains...
you could just use preg_match
if (preg_match('#[\\/:\*\?"<>\|]+#', $text) === 1){ // it contains at least one of those. }I'm not 100% sure which characters need to be escape in the [] though.
Re: Check if text contains...
That depends on what.. umm that # thingy you choose (forgot the name, ill probably find it in php.net).jacek wrote:I'm not 100% sure which characters need to be escape in the [] though.
# is the best for most cases, you can use any character but you must escape it in the regex.
Re: Check if text contains...
I think it's called a hash sign/symbol. In the expression itself it's called an expression delimiter because it tells where the end and begin of the expression is (excluding the optional flag after the second delimiter).
Please check out my CodeCanyon items.
Re: Check if text contains...
Well yeah, there are some control characters and the # in this case that would need to be escape, I just cant remember which of that list are control characters, I think I had a pretty good guess though,Kamal wrote:That depends on what.. umm that # thingy you choose (forgot the name, ill probably find it in php.net).
# is the best for most cases, you can use any character but you must escape it in the regex.
Re: Check if text contains...
In that list, I think you did. I don't think any of the other characters have any special meaning.
The only one I'm not 100% sure of is the colon.
The only one I'm not 100% sure of is the colon.
Please check out my CodeCanyon items.
Re: Check if text contains...
I'll try it out. If it doesn't work I'll let you know