Skip to content

Instantly share code, notes, and snippets.

Mikael Kundert mikaelkundert

Block or report user

Report or block mikaelkundert

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mikaelkundert
mikaelkundert / array_push_after_key.php
Created Mar 20, 2012
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.
View array_push_after_key.php
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;
}
View valid_email.php
<?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;
}
View require_login.php
<?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
You can’t perform that action at this time.