Skip to content

Instantly share code, notes, and snippets.

View mikaelkundert's full-sized avatar

Mikael Kundert mikaelkundert

View GitHub Profile
<?php
/**
* Requires certain username and password to continue.
*
* How to use?
* Simply add require_login("username", "password", "realm") in your PHP code and it will
* require the user to login with given username and password.
*
* @param string The required username
* @param string The required password
<?php
/**
Checks if the email address is valid
@param string $email The email address
@return array Returns preg_match()
*/
function valid_email($email) {
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email)) ? FALSE : TRUE;
}
@mikaelkundert
mikaelkundert / array_push_after_key.php
Created March 20, 2012 12:34
Function which pushes an array element after specified key. Note that array is not catched as reference. You need to re-set your array when using this function.
function array_push_after_key($array, $key, $var) {
$new_array = array();
foreach ($array as $k => $v) {
$new_array[$k] = $v;
if ($k === $key) {
foreach ($var => $kk => $vv) {
$new_array[$kk] = $vv;
}
break;
}