Skip to content

Instantly share code, notes, and snippets.

View fhferreira's full-sized avatar
🏠
Home-Office since 2005

Flávio H. Ferreira fhferreira

🏠
Home-Office since 2005
View GitHub Profile
<?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) {
<?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 );
}
@fhferreira
fhferreira / smushit.php
Last active December 18, 2015 19:09
Classe que encontrei para utilizar a API do smush.it do Yahoo, para redução do tamanho das imagens. Também encontrei essa: https://github.com/codler/Smush.it-API/
<?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 <thepixeldeveloper@googlemail.com>
*/
class smushit
{
const user_agent = 'Smush.it PHP Class (+http://mathew-davies.co.uk)';
<?php
//Não é meu rsrs
$turma=$_POST["turma"];
echo "Turma: ". $turma;
$conteudo=$_POST["conteudo"];
echo "Conteúdo: ". $conteudo;
@fhferreira
fhferreira / ImageScreenCapture.php
Last active December 19, 2015 04:59
Capture Screen
Capture Whole Screen
<?php
$img = imagegrabscreen();
imagepng($img, 'screenshot.png');
?>
imagegrabwindow
(PHP 5 >= 5.2.2)
@fhferreira
fhferreira / RecursiveScanDirectory.php
Last active December 19, 2015 04:59
Recursively Scan a Directory Using PHP SPL DirectoryIterator
<?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);
<?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;
@fhferreira
fhferreira / jquery-mask-nono-digito.js
Last active December 10, 2018 13:31
Jquery Mask Nono Digito
// 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 {
@fhferreira
fhferreira / MaxArray.php
Last active December 27, 2015 11:19
Max Value Recursive in Array PHP
<?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;
@fhferreira
fhferreira / ReformatPhoneNumber.php
Last active December 27, 2015 11:19
Format Number
<?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');