kn0wl3dg3 Posted January 19, 2011 Share Posted January 19, 2011 Any idea why this wouldn't work? It's straight off the w3c site and isn't echoing anything at all $email = "someone@exa mple.com"; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "E-mail is not valid<br />"; } else { echo "E-mail is valid<br />"; } Quote Link to comment Share on other sites More sharing options...
Maq Posted January 19, 2011 Share Posted January 19, 2011 Works for me. Is that everything in your script? Maybe you have something else affecting it. How are you calling it? Quote Link to comment Share on other sites More sharing options...
kn0wl3dg3 Posted January 19, 2011 Author Share Posted January 19, 2011 That's it. That's the whole script. I was just trying to get it to work; I had tried it once before and just wrote a regex instead when I got frustrated. Maybe it's in my .ini settings? Quote Link to comment Share on other sites More sharing options...
Maq Posted January 19, 2011 Share Posted January 19, 2011 That's it. That's the whole script. I was just trying to get it to work; I had tried it once before and just wrote a regex instead when I got frustrated. Maybe it's in my .ini settings? It is? Even without <?php tags? How are you calling it? Quote Link to comment Share on other sites More sharing options...
kn0wl3dg3 Posted January 19, 2011 Author Share Posted January 19, 2011 This is the entire thing: <?php echo 'Learning Email Filter<br />'; $email = "someone@exa mple.com"; echo $email; // to make sure it's being set if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "E-mail is not valid<br />"; } else { echo "E-mail is valid<br />"; } echo 'This will appear after the filter script if it works<br />'; ?> Maybe I'm not calling it correctly since you keep asking how I'm calling it. This was straight off the w3c site, so I wouldn't know if I was doing it wrong Quote Link to comment Share on other sites More sharing options...
Maq Posted January 19, 2011 Share Posted January 19, 2011 What I meant was are you calling it via terminal or browser? Hmm, I copied your script exactly and it's working for me in the CLI and browser. You may have a fatal error, try adding these 2 lines directly under your opening <?php tag: ini_set ("display_errors", "1"); error_reporting(E_ALL); Other than that there must be some environment setting that is affecting it. Quote Link to comment Share on other sites More sharing options...
kn0wl3dg3 Posted January 19, 2011 Author Share Posted January 19, 2011 What I meant was are you calling it via terminal or browser? Hmm, I copied your script exactly and it's working for me in the CLI and browser. You may have a fatal error, try adding these 2 lines directly under your opening <?php tag: ini_set ("display_errors", "1"); error_reporting(E_ALL); Other than that there must be some environment setting that is affecting it. This is what I get with errors on: Fatal error: Call to undefined function filter_var() in /var/www/html/learning/email_filter.php on line 12 As to your other question, terminal or browser, I'm not sure what you mean, but i wrote it in a file and opened it in my browswer, so I'm assuming the answer is browser Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 19, 2011 Share Posted January 19, 2011 You need php version 5.2.0 or greater for filter_var functions. Do you have 5.2.0 or higher? Quote Link to comment Share on other sites More sharing options...
kn0wl3dg3 Posted January 19, 2011 Author Share Posted January 19, 2011 You need php version 5.2.0 or greater for filter_var functions. Do you have 5.2.0 or higher? No...phpinfo() says PHP Version 5.1.6 That must be the issue. Thanks! Quote Link to comment Share on other sites More sharing options...
Maq Posted January 19, 2011 Share Posted January 19, 2011 You need php version 5.2.0 or greater for filter_var functions. Do you have 5.2.0 or higher? Good to know, didn't even see it when I went to the manual... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.