Skip to content

Instantly share code, notes, and snippets.

View MilkZoft's full-sized avatar

Carlos Santana Roldán MilkZoft

View GitHub Profile
@MilkZoft
MilkZoft / email.php
Created January 18, 2012 04:21
codejobs - Validate an email - PHP
<?php
function isEmail($email) {
if((strlen($email) >= 6) and (substr_count($email, "@") === 1) and (substr($email, 0, 1) !== "@") and (substr($email, strlen($email) - 1, 1) !== "@")) {
if((!strstr($email, "'")) and (!strstr($email, "\"")) and (!strstr($email, "\\")) and (!strstr($email, "\$")) and (!strstr($email, " "))) {
if(substr_count($email, ".") >= 1) {
$domain = substr(strrchr($email, "."), 1);
if(strlen($domain) > 1 and strlen($domain) < 5 and (!strstr($domain, "@"))) {
$prev = substr($email, 0, strlen($email) - strlen($domain) - 1);
$last = substr($prev, strlen($prev) - 1, 1);
@MilkZoft
MilkZoft / mobile.php
Created January 18, 2012 04:11
codejobs - How to detect mobile devices? - PHP
<?php
function isMobile($iphone = TRUE, $ipad = TRUE, $android = TRUE , $opera = TRUE, $blackberry = TRUE, $palm = TRUE, $windows = TRUE, $redirect = FALSE, $desktopRedirect = FALSE) {
$mobile = FALSE;
$userAgent = $_SERVER["HTTP_USER_AGENT"];
$accept = $_SERVER["HTTP_ACCEPT"];
$array = array(
"1207" => "1207", "3gso" => "3gso", "4thp" => "4thp", "501i" => "501i", "502i" => "502i", "503i" => "503i",
"504i" => "504i", "505i" => "505i", "506i" => "506i", "6310" => "6310", "6590" => "6590", "770s" => "770s",
"802s" => "802s", "a wa" => "a wa", "acer" => "acer", "acs-" => "acs-", "airn" => "airn", "alav" => "alav",
@MilkZoft
MilkZoft / browser.php
Created January 18, 2012 04:07
codejobs - How to know the user's browser? - PHP
<?php
function browser() {
$browsers = array(
"Opera" => "(Opera)",
"Mozilla Firefox" => "((Firebird)|(Firefox))",
"Galeon" => "(Galeon)",
"Mozilla" => "(Gecko)",
"MyIE" => "(MyIE)",
"Lynx" => "(Lynx)",
"Netscape" => "((Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79))",
@MilkZoft
MilkZoft / html.php
Created January 18, 2012 04:00
codejobs - Clean HTML from a string - PHP
<?php
function cleanHTML($HTML) {
$search = array ('@<script[^>]*?>.*?</script>@si',
'@<[\/\!]*?[^<>]*?>@si',
'@([\r\n])[\s]+@',
'@&(quot|#34);@i',
'@&(amp|#38);@i',
'@&(lt|#60);@i',
'@&(gt|#62);@i',
'@&(nbsp|#160);@i',
@MilkZoft
MilkZoft / compress.php
Created January 18, 2012 03:58
codejobs - Compress a string - PHP
<?php
function compress($string) {
$string = str_replace(array("\r\n", "\r", "\n", "\t", " ", " ", " "), "", $string);
return $string;
}
?>
@MilkZoft
MilkZoft / array.php
Created January 18, 2012 03:54
codejobs - isMultiArray - PHP
<?php
function isMultiArray($multiArray) {
if(is_array($multiArray)) {
foreach($multiArray as $array) {
if(is_array($array)) {
return TRUE;
}
}
}
@MilkZoft
MilkZoft / now.php
Created January 18, 2012 03:49
codejobs - Get the current date in differents languages - PHP
<?php
function now($format, $hour = FALSE, $language = "Spanish") {
if($hour) {
$time = time() + 7200;
$hours = (int) date("H", $time);
$minutes = date("i", $time);
$seconds = date("s", $time);
if($hours > 12) {
if($hours === 13) {
@MilkZoft
MilkZoft / hour.php
Created January 18, 2012 03:45
codejobs - Get hour from a date - PHP
<?php
function getHour($date) {
$date = explode(" ", $date);
if(count($date) > 1) {
$time = explode(":", $date[1]);
} else {
$time = explode(":", $date[0]);
}
@MilkZoft
MilkZoft / remove.php
Created January 18, 2012 03:36
codejobs - Remove Spaces - PHP
<?php
function removeSpaces($text, $trim = FALSE) {
$text = preg_replace("/\s+/", " ", $text);
if($trim) {
return trim($text);
}
return $text;
}
@MilkZoft
MilkZoft / slug.php
Created January 18, 2012 03:34
codejobs - Slug - PHP
<?php
function slug($string) {
$characters = array("Á" => "A", "Ç" => "c", "É" => "e", "Í" => "i", "Ñ" => "n", "Ó" => "o", "Ú" => "u",
"á" => "a", "ç" => "c", "é" => "e", "í" => "i", "ñ" => "n", "ó" => "o", "ú" => "u",
"à" => "a", "è" => "e", "ì" => "i", "ò" => "o", "ù" => "u"
);
$string = strtr($string, $characters);
$string = strtolower(trim($string));
$string = preg_replace("/[^a-z0-9-]/", "-", $string);