Skip to content

Instantly share code, notes, and snippets.

@kkreft
kkreft / PHP remove inline style
Created December 18, 2012 13:52
Remove inline style from HTML code. Does not work with a href.
preg_replace('#(<[a-z ]*)(style=("|\')(.*?)("|\'))([a-z ]*>)#', '\\1\\6', $text);
$dir = '/path/upload';
foreach (new DirectoryIterator($dir) as $fileInfo) {
// if(!in_array($fileInfo->getFilename(), array('.', '..')))
if(!$fileInfo->isDot() && $fileInfo->isDir())
echo $fileInfo->getFilename();
}
@kkreft
kkreft / SQL timestamp curdate
Last active December 18, 2015 17:59
SQL timestamp curdate
SELECT * FROM `table` WHERE DATE(`timestamp`) = CURDATE()
@kkreft
kkreft / [php] cookie expires at midnight
Created June 20, 2013 13:35
[php] cookie expires at midnight
@kkreft
kkreft / [php] wget substitute
Last active December 18, 2015 19:09
[php] wget substitute
file_put_contents('archiwum.zip', file_get_contents('http://dystrybucja-polska.globegroup.pl/archiwum.zip'));
$test = file_get_contents('zip://test.zip#test.txt');
echo $test;
static public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
function xcurl($url,$ref=null,$post=array(),$ua="Mozilla/5.0 (X11; Linux x86_64; rv:2.2a1pre) Gecko/20110324 Firefox/4.2a1pre",$print=false) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
if(!empty($ref)) {
curl_setopt($ch, CURLOPT_REFERER, $ref);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
function detectCityByIP($ip) {
$default = 'Hollywood, CA';
if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost')
$ip = '8.8.8.8';
$curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';
$url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip);