Get current date in isoformat
Open database connection
Execute a query
Remote IP address
Generate random string
base64 url encrypt
base64 url decrypt
Send email
Check if email is valid
Censor word from a database
Encode email
Force download
Inverse color
Xor encryption
Syntax Highlighting
Jpg to ASCII
Generate random string
Html to text
Convert url to spam
Get destination url of a spam
NEXT TIME WHEN U POST CODES DO ADD IN IN [CODE [/CODE] FORMATS PLEASE
Code:
function isoDate() { return date("Y-m-d"); }
Code:
function open_connection($host, $username, $password, $database) { $conn = mysql_connect($host, $username, $password) or trigger_error(mysql_error(), E_USER_ERROR); mysql_select_db($database), $this->conn); }
Code:
function query($query, $conn) { $rSet = mysql_query($query, $conn)) or die("Query failed: ".mysql_error()); return $rSet; }
Code:
function getRemoteIPAddress() { $ip = $_SERVER['REMOTE_ADDR']; return $ip; }
Code:
function password($length) { srand((double)microtime()*100); return substr(md5(uniqid(rand())),0,$length); }
Code:
function base64url_encode($plainText) { $base64 = base64_encode($plainText); $base64url = strtr($base64, '+/=', '-_,'); return $base64url; }
Code:
function base64url_decode($plainText) { $base64url = strtr($plainText, '-_,', '+/='); $base64 = base64_decode($base64url); return $base64; }
Code:
function mailMsg($to, $subject, $message, $headers) { mail($to,$subject,$message,$headers); }
Code:
function email_validate { $email = $_POST['email']; if(preg_match("~([a-zA-Z0-9!#$%&'*+-/=?^_`{|}~])@([a-zA-Z0-9-]).([a-zA-Z0-9]{2,4})~",$email)) { echo 'This is a valid email.'; } else { echo 'This is an invalid email.'; } }
Code:
function censor($msg, $collumn, $table) { // uses database global $db; $rSet = $db->query("select * from $table"); while ($tRow = mysql_fetch_assoc($rSet)) { $msg = str_replace($tRow[$collumn], "[Censored]", $msg); } return $msg; }
Code:
function encode_email($email='info@domain.com', $linkText='Contact Us', $attrs ='class="emailencoder"' ) { $email = str_replace('@', '&#64;', $email); $email = str_replace('.', '&#46;', $email); $email = str_split($email, 5); $linkText = str_replace('@', '&#64;', $linkText); $linkText = str_replace('.', '&#46;', $linkText); $linkText = str_split($linkText, 5); $part1 = '<a href="ma'; $part2 = 'ilto&#58;'; $part3 = '" '. $attrs .' >'; $part4 = '</a>'; $encoded = '<script type="text/javascript">'; $encoded .= "document.write('$part1');"; $encoded .= "document.write('$part2');"; foreach($email as $e) { $encoded .= "document.write('$e');"; } $encoded .= "document.write('$part3');"; foreach($linkText as $l) { $encoded .= "document.write('$l');"; } $encoded .= "document.write('$part4');"; $encoded .= '</script>'; return $encoded; }
Code:
function force_download($file) { if ((isset($file))&&(file_exists($file))) { header("Content-length: ".filesize($file)); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $file . '"'); readfile("$file"); } else { echo "No file selected"; } }
Code:
function color_inverse($color) { $color = str_replace('#', '', $color); if (strlen($color) != 6){ return '00'; } $rgb = ''; for ($x=0;$x<3;$x++){ $c = 255 - hexdec(substr($color,(2*$x),2)); $c = ($c < 0) ? 0 : dechex($c); $rgb .= (strlen($c) < 2) ? '0'.$c : $c; } return '#'.$rgb; }
Code:
function XOREncryption($InputString, $KeyPhrase){ $KeyPhraseLength = strlen($KeyPhrase); // Loop trough input string for ($i = 0; $i < strlen($InputString); $i++){ // Get key phrase character position $rPos = $i % $KeyPhraseLength; // Magic happens here: $r = ord($InputString[$i]) ^ ord($KeyPhrase[$rPos]); // Replace characters $InputString[$i] = chr($r); } return $InputString; }
Code:
function syntax_highlight($code){ // this matches --> "foobar" <-- $code = preg_replace( '/"(.*?)"/U', '"<span style="color: #007F00">$1</span>"', $code ); // hightlight functions and other structures like --> function foobar() <--- $code = preg_replace( '/(\s)\b(.*?)((\b|\s)\()/U', '$1<span style="color: #0000ff">$2</span>$3', $code ); // Match comments (like /* */): $code = preg_replace( '/(\/\/)(.+)\s/', '<span style="color: #660066; background-color: #FFFCB1;"><i>$0</i></span>', $code ); $code = preg_replace( '/(\/\*.*?\*\/)/s', '<span style="color: #660066; background-color: #FFFCB1;"><i>$0</i></span>', $code ); // hightlight braces: $code = preg_replace('/(\(|\[|\{|\}|\]|\)|\->)/', '<strong>$1</strong>', $code); // hightlight variables $foobar $code = preg_replace( '/(\$[a-zA-Z0-9_]+)/', '<span style="color: #0000B3">$1</span>', $code ); /* The \b in the pattern indicates a word boundary, so only the distinct ** word "web" is matched, and not a word partial like "webbing" or "cobweb" */ // special words and functions $code = preg_replace( '/\b(print|echo|new|function)\b/', '<span style="color: #7F007F">$1</span>', $code ); return $code; }
Code:
function getext($filename) { $pos = strrpos($filename,'.'); $str = substr($filename, $pos); return $str; } if(!isset($_POST['submit'])){ ?> <form action="<?echo $_SERVER['PHP_SELF'];?>" method="post"> JPG img URL: <input type="text" name="image"><br> <input type="submit" name="submit" value="Create"> </form> <? }else{ $image = $_POST['image']; $ext = getext($image); if($ext == ".jpg"){ $img = ImageCreateFromJpeg($image); } else{ echo'Wrong File Type'; } $width = imagesx($img); $height = imagesy($img); for($h=0;$h<$height;$h++){ for($w=0;$w<=$width;$w++){ $rgb = ImageColorAt($img, $w, $h); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; if($w == $width){ echo '<br>'; }else{ echo '<span style="color:rgb('.$r.','.$g.','.$b.');">#</span>'; } } } }
Code:
function randomString { $string = "abcdefghijklmnopqrstuvwxyz0123456789"; for($i=0;$i<25;$i++) { $pos = rand(0,36); $str .= $string{$pos}; } echo $str; }
Code:
function html2txt($document) { $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<[?]php[^>].*?[?]>@si', //scripts php '@<[?][^>].*?[?]>@si', //scripts php '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA );$text = preg_replace($search, '', $document); return $text; }
Code:
function getTinyUrl($url) { return file_get_contents("http://spam.com/api-create.php?url=".$url); }
Code:
function untinyUrl($spam){ if($fp = fsockopen ("spam.com", 80, $errno, $errstr, 30)){ if ($fp) { fputs ($fp, "HEAD /$spam HTTP/1.0\r\nHost: spam.com\r\n\r\n"); $headers = ''; while (!feof($fp)) { $headers .= fgets ($fp,128); } fclose ($fp); } $arr1=explode("Location:",$headers); $arr=explode("\n",trim($arr1[1])); echo trim($arr[0]); } }
Comment