本文整理汇总了PHP中filter_var函数的典型用法代码示例。如果您正苦于以下问题:PHP filter_var函数的具体用法?PHP filter_var怎么用?PHP filter_var使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filter_var函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string $email
*/
function __construct($email)
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid email', $email));
}
$this->email = $email;
}
示例2: parseURL
protected function parseURL()
{
if (isset($_GET['url'])) {
$url = preg_replace('/public\\//', '', $_GET['url']);
return explode("/", filter_var(rtrim($url, "/"), FILTER_SANITIZE_URL));
}
}
示例3: __construct
public function __construct($name = 'Email', array $config = [])
{
parent::__construct($name, $config);
$this->validators[] = function ($value) {
return filter_var($value, FILTER_VALIDATE_EMAIL) ? true : "Invalid email address: {$value}";
};
}
示例4: Email
public function Email($email, $reemail)
{
if (empty($email)) {
$this->errors[] = "You must provide a valid E-Mail.";
}
//check if provided email is valid, but first check that the user typed something in.
if (!empty($email)) {
if ($email !== $reemail) {
$this->errors[] = "The E-Mail's that you provided do not match.";
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->errors[] = "The E-Mail that you provided is not valid.";
}
}
if (filter_var($email, FILTER_VALIDATE_EMAIL) && $email == $reemail) {
$stmt = $this->mysqli->prepare("SELECT * FROM temp_users,users WHERE users.email = ? OR temp_users.email = ?") or die("There was an error of some sort.");
$stmt->bind_param('ss', $email, $email);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
// email is found, throw out error
$this->errors[] = "That E-Mail is already in use.";
}
$stmt->free_result();
$stmt->close();
}
}
示例5: validate
/**
* Validates the given $value
* Checks if it is a valid (possible) floating point value
*
* @param float $value
* @return ValidationResult
*/
public function validate($value)
{
if (filter_var($value, FILTER_VALIDATE_FLOAT, array('options' => array('decimal' => $this->decimal))) === false) {
return new ValidationResult(false, 'Not a floating point value');
}
return new ValidationResult(true);
}
示例6: process_form
public function process_form($form_values, $data)
{
$flash_id = 'fw_ext_contact_form_process';
if (empty($form_values)) {
FW_Flash_Messages::add($flash_id, __('Unable to process the form', 'fw'), 'error');
return;
}
$form_id = FW_Request::POST('fw_ext_forms_form_id');
if (empty($form_id)) {
FW_Flash_Messages::add($flash_id, __('Unable to process the form', 'fw'), 'error');
}
$form = $this->get_db_data($this->get_name() . '-' . $form_id);
if (empty($form)) {
FW_Flash_Messages::add($flash_id, __('Unable to process the form', 'fw'), 'error');
}
$to = $form['email_to'];
if (!filter_var($to, FILTER_VALIDATE_EMAIL)) {
FW_Flash_Messages::add($flash_id, __('Invalid destination email (please contact the site administrator)', 'fw'), 'error');
return;
}
$entry_data = array('form_values' => $form_values, 'shortcode_to_item' => $data['shortcode_to_item']);
$result = fw_ext_mailer_send_mail($to, $this->get_db_data($this->get_name() . '-' . $form_id . '/subject_message', ''), $this->render_view('email', $entry_data), $entry_data);
if ($result['status']) {
FW_Flash_Messages::add($flash_id, $this->get_db_data($this->get_name() . '-' . $form_id . '/success_message', __('Message sent!', 'fw')), 'success');
} else {
FW_Flash_Messages::add($flash_id, $this->get_db_data($this->get_name() . '-' . $form_id . '/failure_message', __('Oops something went wrong.', 'fw')) . ' <em style="color:transparent;">' . $result['message'] . '</em>', 'error');
}
}
示例7: process
function process()
{
$email = $this->input->post('email');
$password = $this->input->post('password');
$name = $this->input->post('name');
if ($email == '') {
$this->session->set_flashdata('error', 'Email is required');
redirect('register');
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->session->set_flashdata('error', 'Enter your Valid email id.');
redirect('register');
}
if ($password == '') {
$this->session->set_flashdata('error', 'Enter your Password');
redirect('register');
}
$data = array('email' => $email, 'password' => $password, 'name' => $name, 'date' => date('d-m-y'), 'status' => '1');
$sql = "SELECT * FROM user WHERE email='" . $data['email'] . "'";
$query = $this->db->query($sql);
if ($query->num_rows() == 0) {
$this->db->insert('user', $data);
$this->session->set_flashdata('error', 'Registered Successfully, Thank you !');
redirect('cart');
}
if ($query->num_rows() == 1) {
$this->session->set_flashdata('error', 'Email Address Aleready Exists');
redirect('register');
}
}
示例8: parseUrl
public function parseUrl()
{
if (isset($_GET['url'])) {
//echo $_GET['url'];
return $url = explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
}
}
示例9: filter
/**
* Filter the redirect url
*
* @param mixed $value
* @return string|null
*/
public function filter($value)
{
if (!$this->validator->isValid($value)) {
return null;
}
return urldecode(filter_var($value, FILTER_SANITIZE_URL));
}
示例10: __construct
/**
* Sets GET and POST into local properties
*/
public function __construct(&$conf = false)
{
// parse vars from URI
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) {
$qrystr = str_replace('r=', '', filter_var($_SERVER['QUERY_STRING']));
if (!strstr($qrystr, 'exe/')) {
$this->parseUri($qrystr);
} else {
$key = explode('/', $qrystr);
if (isset($key[1])) {
$this->_exe = $key[1];
}
}
unset($qrystr);
}
// vars from GET
if ($_GET) {
while (list($key, $value) = each($_GET)) {
if ($key != 'r') {
$this->{$key} = $value;
}
}
}
// vars from POST
if ($_POST) {
while (list($key, $value) = each($_POST)) {
$this->{$key} = $value;
}
}
// vars from FILES
if ($_FILES) {
$this->setFiles($conf);
}
}
示例11: mergecnf
/**
* Merge config function
* @author f0o <f0o@devilcode.org>
* @copyright 2015 f0o, LibreNMS
* @license GPL
* @package LibreNMS
* @subpackage Config
*/
function mergecnf($obj)
{
$pointer = array();
$val = $obj['config_value'];
$obj = $obj['config_name'];
$obj = explode('.', $obj, 2);
if (!isset($obj[1])) {
if (filter_var($val, FILTER_VALIDATE_INT)) {
$val = (int) $val;
} else {
if (filter_var($val, FILTER_VALIDATE_FLOAT)) {
$val = (double) $val;
} else {
if (filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null) {
$val = filter_var($val, FILTER_VALIDATE_BOOLEAN);
}
}
}
if (!empty($obj[0])) {
return array($obj[0] => $val);
} else {
return array($val);
}
} else {
$pointer[$obj[0]] = mergecnf(array('config_name' => $obj[1], 'config_value' => $val));
}
return $pointer;
}
示例12: record_coupon_application
function record_coupon_application($sub_id = false, $pricing = false)
{
global $blog_id;
$global = defined('MEMBERSHIP_GLOBAL_TABLES') && filter_var(MEMBERSHIP_GLOBAL_TABLES, FILTER_VALIDATE_BOOLEAN);
// Create transient for 1 hour. This means the user has 1 hour to redeem the coupon after its been applied before it goes back into the pool.
// If you want to use a different time limit use the filter below
$time = apply_filters('membership_apply_coupon_redemption_time', HOUR_IN_SECONDS);
// Grab the user account as we should be logged in by now
$user = wp_get_current_user();
$transient_name = 'm_coupon_' . $blog_id . '_' . $user->ID . '_' . $sub_id;
$transient_value = array('coupon_id' => $this->_coupon->id, 'user_id' => $user->ID, 'sub_id' => $sub_id, 'prices_w_coupon' => $pricing);
// Check if a transient already exists and delete it if it does
if ($global && function_exists('get_site_transient')) {
$trying = get_site_transient($transient_name);
if ($trying != false) {
// We have found an existing coupon try so remove it as we are using a new one
delete_site_transient($transient_name);
}
set_site_transient($transient_name, $transient_value, $time);
} else {
$trying = get_transient($transient_name);
if ($trying != false) {
// We have found an existing coupon try so remove it as we are using a new one
delete_transient($transient_name);
}
set_transient($transient_name, $transient_value, $time);
}
}
示例13: __construct
/**
* Constructor
* @since Version 3.9
* @param int $routeId
* @param object $gtfsProvider
*/
public function __construct($routeId = null, $gtfsProvider = null)
{
if (function_exists("getRailpageConfig")) {
$this->Config = getRailpageConfig();
}
$this->adapter = new Adapter(array("driver" => "Mysqli", "database" => $this->Config->GTFS->PTV->db_name, "username" => $this->Config->GTFS->PTV->db_user, "password" => $this->Config->GTFS->PTV->db_pass, "host" => $this->Config->GTFS->PTV->db_host));
$this->db = new Sql($this->adapter);
if (is_object($gtfsProvider)) {
$this->Provider = $gtfsProvider;
}
/**
* Fetch the route
*/
if (!filter_var($routeId, FILTER_VALIDATE_INT)) {
return;
}
$query = sprintf("SELECT route_id, route_short_name, route_long_name, route_desc, route_type, route_url, route_color, route_text_color FROM %s_routes WHERE id = %s", $this->Provider->getDbPrefix(), $routeId);
$result = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE);
if (!is_array($result)) {
return;
}
foreach ($result as $row) {
$row = $row->getArrayCopy();
$this->id = $routeId;
$this->route_id = $row['route_id'];
$this->short_name = $row['route_short_name'];
$this->long_name = $row['route_long_name'];
$this->desc = $row['route_desc'];
$this->type = $row['route_type'];
}
}
示例14: submenu_parameters
function submenu_parameters()
{
$isWordpressGallery = filter_var(get_option('owl_carousel_wordpress_gallery', false), FILTER_VALIDATE_BOOLEAN) ? 'checked' : '';
$orderBy = get_option('owl_carousel_orderby', 'post_date');
$orderByOptions = array('post_date', 'title');
echo '<div class="wrap owl_carousel_page">';
echo '<?php update_option("owl_carousel_wordpress_gallery", $_POST["wordpress_gallery"]); ?>';
echo '<h2>' . __('Owl Carousel parameters', 'owl-carousel-domain') . '</h2>';
echo '<form action="' . plugin_dir_url(__FILE__) . 'save_parameter.php" method="POST" id="owlcarouselparameterform">';
echo '<h3>' . __('Wordpress Gallery', 'owl-carousel-domain') . '</h3>';
echo '<input type="checkbox" name="wordpress_gallery" ' . $isWordpressGallery . ' />';
echo '<label>' . __('Use Owl Carousel with Wordpress Gallery', 'owl-carousel-domain') . '</label>';
echo '<br />';
echo '<label>' . __('Order Owl Carousel elements by ', 'owl-carousel-domain') . '</label>';
echo '<select name="orderby" />';
foreach ($orderByOptions as $option) {
echo '<option value="' . $option . '" ' . ($option == $orderBy ? 'selected="selected"' : '') . '>' . $option . '</option>';
}
echo '</select>';
echo '<br />';
echo '<br />';
echo '<input type="submit" class="button-primary owl-carousel-save-parameter-btn" value="' . __('Save changes', 'owl-carousel-domain') . '" />';
echo '<span class="spinner"></span>';
echo '</form>';
echo '</div>';
}
示例15: importCommand
/**
* Import command
*
* @param string $icsCalendarUri
* @param int $pid
*/
public function importCommand($icsCalendarUri = NULL, $pid = NULL)
{
if ($icsCalendarUri === NULL || !filter_var($icsCalendarUri, FILTER_VALIDATE_URL)) {
$this->enqueueMessage('You have to enter a valid URL to the iCalendar ICS', 'Error', FlashMessage::ERROR);
}
if (!MathUtility::canBeInterpretedAsInteger($pid)) {
$this->enqueueMessage('You have to enter a valid PID for the new created elements', 'Error', FlashMessage::ERROR);
}
// fetch external URI and write to file
$this->enqueueMessage('Start to checkout the calendar: ' . $icsCalendarUri, 'Calendar', FlashMessage::INFO);
$relativeIcalFile = 'typo3temp/ical.' . GeneralUtility::shortMD5($icsCalendarUri) . '.ical';
$absoluteIcalFile = GeneralUtility::getFileAbsFileName($relativeIcalFile);
$content = GeneralUtility::getUrl($icsCalendarUri);
GeneralUtility::writeFile($absoluteIcalFile, $content);
// get Events from file
$icalEvents = $this->getIcalEvents($absoluteIcalFile);
$this->enqueueMessage('Found ' . sizeof($icalEvents) . ' events in the given calendar', 'Items', FlashMessage::INFO);
$events = $this->prepareEvents($icalEvents);
$this->enqueueMessage('This is just a first draft. There are same missing fields. Will be part of the next release', 'Items', FlashMessage::ERROR);
return;
foreach ($events as $event) {
$eventObject = $this->eventRepository->findOneByImportId($event['uid']);
if ($eventObject instanceof Event) {
// update
$eventObject->setTitle($event['title']);
$eventObject->setDescription($this->nl2br($event['description']));
$this->eventRepository->update($eventObject);
$this->enqueueMessage('Update Event Meta data: ' . $eventObject->getTitle(), 'Update');
} else {
// create
$eventObject = new Event();
$eventObject->setPid($pid);
$eventObject->setImportId($event['uid']);
$eventObject->setTitle($event['title']);
$eventObject->setDescription($this->nl2br($event['description']));
$configuration = new Configuration();
$configuration->setType(Configuration::TYPE_TIME);
$configuration->setFrequency(Configuration::FREQUENCY_NONE);
/** @var \DateTime $startDate */
$startDate = clone $event['start'];
$startDate->setTime(0, 0, 0);
$configuration->setStartDate($startDate);
/** @var \DateTime $endDate */
$endDate = clone $event['end'];
$endDate->setTime(0, 0, 0);
$configuration->setEndDate($endDate);
$startTime = $this->dateTimeToDaySeconds($event['start']);
if ($startTime > 0) {
$configuration->setStartTime($startTime);
$configuration->setEndTime($this->dateTimeToDaySeconds($event['end']));
$configuration->setAllDay(FALSE);
} else {
$configuration->setAllDay(TRUE);
}
$eventObject->addCalendarize($configuration);
$this->eventRepository->add($eventObject);
$this->enqueueMessage('Add Event: ' . $eventObject->getTitle(), 'Add');
}
}
}