This file contains 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 | |
class myDBH { | |
private $db_info = array("host" => "localhost", "dbname" => "myDB", "username" => "myDB_user", "password" => "myDB_password"); | |
private $dbh; | |
public static $instance = NULL; | |
public function __construct(array $db_info = null) { | |
if(isset($db_info)) { | |
foreach($db_info as $key_name => $key_value) { |
This file contains 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 highlighter_text($text, $words) | |
{ | |
$split_words = explode( " " , $words ); | |
foreach($split_words as $word) | |
{ | |
$color = "#e5e5e5"; | |
$text = preg_replace("|($word)|Ui" , | |
"<span style=\"background:".$color.";\"><b>$1</b></span>" , $text ); | |
} |
This file contains 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 | |
/** | |
* Description: Compresses images using Smush.it | |
* http://www.smushit.com/ysmush.it/ws.php?img=http://images.google.com/intl/pt-BR_ALL/images/logos/images_logo_lg.gif | |
* @license MIT | |
* @author Mathew Davies <[email protected]> | |
*/ | |
class smushit | |
{ | |
const user_agent = 'Smush.it PHP Class (+http://mathew-davies.co.uk)'; |
This file contains 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 | |
//Não é meu rsrs | |
$turma=$_POST["turma"]; | |
echo "Turma: ". $turma; | |
$conteudo=$_POST["conteudo"]; | |
echo "Conteúdo: ". $conteudo; |
This file contains 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
Capture Whole Screen | |
<?php | |
$img = imagegrabscreen(); | |
imagepng($img, 'screenshot.png'); | |
?> | |
imagegrabwindow | |
(PHP 5 >= 5.2.2) |
This file contains 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 IMAGE files recursively from Root and all sub-folders | |
* Skip folders in our list of results | |
* LEAVES_ONLY mode makes sure ONLY FILES/Leafs endpoint is returned | |
* Make sure file extension is in our Images extensions array | |
*/ | |
$path = 'E:\Server\_ImageOptimize\img\testfiles'; | |
$directory = new RecursiveDirectoryIterator($path,RecursiveDirectoryIterator::SKIP_DOTS); |
This file contains 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 | |
/* strpos that takes an array of values to match against a string | |
* note the stupid argument order (to match strpos) | |
*/ | |
function strpos_arr($haystack, $needle) { | |
if(!is_array($needle)) $needle = array($needle); | |
foreach($needle as $what) { | |
if(($pos = strpos($haystack, $what))!==false) return $pos; | |
} | |
return false; |
This file contains 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
// jQuery Masked Input | |
$('#celular').mask("(99) 9999-9999?9").ready(function(event) { | |
var target, phone, element; | |
target = (event.currentTarget) ? event.currentTarget : event.srcElement; | |
phone = target.value.replace(/\D/g, ''); | |
element = $(target); | |
element.unmask(); | |
if(phone.length > 10) { | |
element.mask("(99) 99999-999?9"); | |
} else { |
This file contains 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 MaxArray($arr){ | |
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr)); | |
// initialize $max | |
$iterator->next(); | |
$max = $iterator->current(); | |
// "iterate" over all values | |
foreach($iterator as $v) { | |
if ( $v > $max ) { | |
$max = $v; |
This file contains 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 ReformatPhoneNumber($number){ | |
$match2 = preg_match('/^\d(?:[-\s]?\d){6,11}$/', $number); | |
if( $match2 ){ | |
echo preg_replace( '/[^0-9]/', '', $number ); | |
}else{ | |
throw new Exception("Invalid phone number"); | |
} | |
} | |
echo ReformatPhoneNumber('012-345 69'); |