/ Published in: PHP

Checks if a given address is local. Useful for setting up the dev environment automatically.
NOTE: It's not intended for validation!
NOTE: It's not intended for validation!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function is_local($str) { return (bool) preg_match('/^local\.|\.local$|^localhost$|^127\.0\.0\.1$|^::1$|^10\.|^169\.254\.|^172\.(?:1[6-9]|2[0-9]|[3[0-1]])\.|^192\.168\./', $str); } // Examples:
Comments
