This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Get and save remote file PHP script | |
http://egza.org/ | |
*/ | |
error_reporting(E_ALL); | |
if(!isset($_GET['url'])){ | |
die("url parameter is required."); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = "SELECT * FROM table1"; | |
$my_connection = mysql_connect ( "localhost" , "user_name" , "pass" ); | |
if (!$my_connection) | |
{ | |
die( 'Could not connect to database : ' . mysql_error()) ; | |
} | |
mysql_set_charset('utf8'); | |
$db_selected = mysql_select_db('database_name', $my_connection); | |
if (!$db_selected) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function prettyDate($date){ | |
$time = strtotime($date); | |
$now = time(); | |
$ago = $now - $time; | |
if($ago < 60){ | |
$when = round($ago); | |
$s = ($when == 1)?"second":"seconds"; | |
return "$when $s ago"; | |
}elseif($ago < 3600){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function limit_words($string, $word_limit) { | |
$string = strip_tags($string); | |
$words = explode(' ', strip_tags($string)); | |
$return = trim(implode(' ', array_slice($words, 0, $word_limit))); | |
if(strlen($return) < strlen($string)){ | |
$return .= '...'; | |
} | |
return $return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function up($str){ | |
return strtoupper($str); | |
} | |
function camelCaseGetParts($str, $count=0) | |
{ | |
$parts = array() ; | |
$partIndex = 1 ; | |
$len = strlen($str) ; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function shorten($id, $alphabet='0123456789abcdefghijklmnopqrstuvwxyz') | |
{ | |
$base = strlen($alphabet); | |
$short = ''; | |
while($id) { | |
$id = ($id-($r=$id%$base))/$base; | |
$short = $alphabet{$r} . $short; | |
}; | |
return $short; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function base64_url_encode($input) | |
{ | |
return strtr(base64_encode($input), '+/=', '-_,'); | |
} | |
function base64_url_decode($input) | |
{ | |
return base64_decode(strtr($input, '-_,', '+/=')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$str= "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut elit id mi ultricies adipiscing. Nulla facilisi. Praesent pulvinar, sapien vel feugiat vestibulum, nulla dui pretium orci, non ultricies elit lacus quis ante. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam pretium ullamcorper urna quis iaculis. Etiam ac massa sed turpis tempor luctus. Curabitur sed nibh eu elit mollis congue. Praesent ipsum diam, consectetur vitae ornare a, aliquam a nunc. In id magna pellentesque tellus posuere adipiscing. Sed non mi metus, at lacinia augue. Sed magna nisi, ornare in mollis in, mollis sed nunc. Etiam at justo in leo congue mollis. Nullam in neque eget metus hendrerit scelerisque eu non enim. Ut malesuada lacus eu nulla bibendum id euismod urna sodales."; | |
function base64_url_encode($input) | |
{ | |
$compressed = gzcompress($input, 9); | |
return strtr(base64_encode($compressed), '+/=', '-_,'); | |
} | |
function base64_url_decode($input) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public static function validate_url($str) | |
{ | |
if (empty($str)) | |
return true; | |
if (strpos($str, "http") === false) { | |
return false; | |
} else { | |
return (!preg_match('/^(http|https|ftp)); //\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+)); //?(\d+)?\/?/i', $str)) ? FALSE : TRUE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public static function validate_email($email) | |
{ | |
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; | |
} | |
?> |