note 54981 modified in function.stristr by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 20:08:12 +0000 |
| Subject: | note 54981 modified in function.stristr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147180@lists.php.net to get a copy of this message | ||
You can use strstr() or stristr() to validate data!
Check this out:
<?php
function validate_email($input) {
if (!stristr($input, '@')) {
return false;
}
return true;
}
function validate_url($input) {
if (!stristr($input, 'http://')) {
return false;
}
return true;
}
?>
Simple example:
<?php
if (!validate_email($_POST['email'])) {
print 'You did not enter a valid email adress';
}
if (!validate_url($_POST['url'])) {
print 'You did not enter a valid url.';
}
?>
--was--
You can use strstr() or strstri() to validate data!
Check this out:
<?php
function validate_email($input) {
if (!strstri($input, '@')) {
return false;
}
return true;
}
function validate_url($input) {
if (!strstri($input, 'http://')) {
return false;
}
return true;
}
?>
Simple example:
<?php
if (!validate_email($_POST['email'])) {
print 'You did not enter a valid email adress';
}
if (!validate_url($_POST['url'])) {
print 'You did not enter a valid url.';
}
?>
http://php.net/manual/en/function.stristr.php