Jump to content

preg_match


Tom10

Recommended Posts

Hi, i don't have a problem with this code it works fine, but i don't understand it.

if(preg_match("#[^\w\/\&\\?\=\.]#", $fullURL)) {

	include 'deny.php';
	die();

} else {

}

My understanding is that \w includes a-z Z-A so i don't understand when i load the page it doesn't instantly go to deny.php it make's sense to put the include 'deny.php' and die(); in else?

 

Not sure if you understand what i mean, please say if you don't i will try to explain what i mean better.

Link to comment
https://forums.phpfreaks.com/topic/294624-preg_match/
Share on other sites

The ^ character inside of a character class ([ ]) inverts the pattern. This is a way of creating a whitelist of allowed characters. If $fullURL contains characters that are outside of the allowed whitelist, then the pattern will match and run the code inside the conditional.

 

Hopefully that makes sense.

Link to comment
https://forums.phpfreaks.com/topic/294624-preg_match/#findComment-1505744
Share on other sites

The ^ character inside of a character class ([ ]) inverts the pattern. This is a way of creating a whitelist of allowed characters. If $fullURL contains characters that are outside of the allowed whitelist, then the pattern will match and run the code inside the conditional.

 

Hopefully that makes sense.

Thank you so much, scootstah.

 

That made a lot of sense and cleared that up for me :)

Link to comment
https://forums.phpfreaks.com/topic/294624-preg_match/#findComment-1505745
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.