Skip to content

Instantly share code, notes, and snippets.

View madeinnordeste's full-sized avatar
:octocat:
Coding

Luiz Alberto S. Ribeiro madeinnordeste

:octocat:
Coding
View GitHub Profile
@madeinnordeste
madeinnordeste / PHP-parse-CSV.php
Created May 3, 2014 01:00
PHP - Parse CSV files
<?php
$fh = fopen("contacts.csv", "r");
while($line = fgetcsv($fh, 1000, ",")) {
echo "Contact: {$line[1]}";
}
?>
@madeinnordeste
madeinnordeste / PHP-script-tags-to-bottom.php
Created May 3, 2014 01:02
PHP - Move Script TAGS to bottom
<?php
$source = file_get_contents("http://www.mywebsite.com");
preg_match_all("/<script(.|\n)*?<\/script>/", $source, $matches);
$source = preg_replace("/<script(.|\n)*?<\/script>/", '', $source);
$scripts = implode('', $matches[0]);
@madeinnordeste
madeinnordeste / PHP-get-emails-from-string.php
Created May 3, 2014 01:06
PHP - Get emails address from string
<?php
function extract_emails($str){
$regexp = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
preg_match_all($regexp, $str, $m);
return isset($m[0]) ? $m[0] : array();
}
$test_string = 'This is a test string...
<?php
$from = new DateTime('0000-00-00 00:00:00');
$to = new DateTime('now');
$interval = $to->diff($from);
//2011 years, 4 months, 5 days, 11 hours, 13 minutes, 49 seconds
echo $interval->format('%Y years, %m months, %d days, %H hours, %i minutes, %s seconds');
?>
@madeinnordeste
madeinnordeste / PHP-dBug.php
Created May 3, 2014 01:10
PHP - dBug function
<?php
/*********************************************************************************************************************\
* LAST UPDATE
* ============
* March 22, 2007
*
*
* AUTHOR
* =============
* Kwaku Otchere
@madeinnordeste
madeinnordeste / PHP-check-if-string-contains-another-string.php
Created May 3, 2014 01:12
PHP - Check if a string contains another string
<?php
function contains($str, $content, $ignorecase=true){
if ($ignorecase){
$str = strtolower($str);
$content = strtolower($content);
}
return strpos($content,$str) ? true : false;
}
<?php
//Open file
$handler = fopen ("file.txt", "r");
//Read file, line to line
while (!feof ($handler)) {
//Read one line
$line = fgets($handler, 4096);
@madeinnordeste
madeinnordeste / wp-Get-Post-Images.php
Last active August 29, 2015 14:00
Wordpress : Get Post Images
<?php
//in theme function.php
//get post images
function post_get_images($ind=NULL){
global $post;
$url_alternative = 'http://www.google.com.br/intl/en_com/images/srpr/logo1w.png';
@madeinnordeste
madeinnordeste / wp-popular-posts.php
Last active August 29, 2015 14:00
Wordpress : Popular Posts
@madeinnordeste
madeinnordeste / wp-include-jQuery.php
Last active August 29, 2015 14:00
Wordpress : Include jQuery
<?php wp_enqueue_script("jquery"); ?>