Skip to content

Instantly share code, notes, and snippets.

View mazhar266's full-sized avatar
💭
I may be slow to respond.

Mazhar Ahmed mazhar266

💭
I may be slow to respond.
View GitHub Profile
@mazhar266
mazhar266 / UTF8_STRLEN.php
Created February 18, 2012 09:55
strlen of utf8 unicode characters
<?php
function utf8_strlen ($s)
{
$c = strlen($s); $l = 0;
for ($i = 0; $i < $c; ++$i)
if ((ord($s[$i]) & 0xC0) != 0x80)
++$l;
return $l;
}
@mazhar266
mazhar266 / file_get_contents_curl.php
Created April 12, 2012 10:02
file_get_contents_curl
<?php
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
@mazhar266
mazhar266 / get_twitter_status.php
Created April 12, 2012 10:06
get_twitter_status
<?php
function get_twitter_status ($twitter_id, $hyperlinks = true)
{
$c = curl_init ();
curl_setopt ($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1");
curl_setopt ($c, CURLOPT_RETURNTRANSFER, 1);
$src = curl_exec ($c);
curl_close ($c);
preg_match ('/<text>(.*)<\/text>/', $src, $m);
$status = htmlentities ($m[1]);
@mazhar266
mazhar266 / csscompress.php
Created April 12, 2012 10:22
CSS Compress
<?php
header('Content-type: text/css');
ob_start("compress");
function compress($buffer) {
/* remove comments */
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}
@mazhar266
mazhar266 / execute.php
Created April 12, 2012 10:23
time to execute
<?php
//Create a variable for start time
$time_start = microtime(true);
// Place your PHP/HTML/JavaScript/CSS/Etc. Here
//Create a variable for end time
$time_end = microtime(true);
//Subtract the two times to get seconds
$time = $time_end - $time_start;
@mazhar266
mazhar266 / generateSlug.php
Created April 21, 2012 09:18
SEO style URL making (removing unsupported)
<?php
function generateSlug($phrase, $maxLength)
{
$result = strtolower($phrase);
$result = preg_replace("/[^a-z0-9\s-]/", "", $result);
$result = trim(preg_replace("/[\s-]+/", " ", $result));
$result = trim(substr($result, 0, $maxLength));
$result = preg_replace("/\s/", "-", $result);
@mazhar266
mazhar266 / ajax.php
Created May 7, 2012 13:05
detect ajax call
<?php
/* decide what the content should be up here .... */
$content = get_content(); //generic function;
/* AJAX check */
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
/* special ajax here */
die($content);
}
@mazhar266
mazhar266 / pagination.css
Created February 20, 2013 13:29
Bootstrap pagination center align.css
.pagination {
word-spacing: -1em !important;
text-align:center !important;
}
.pagination li {
display: -moz-inline-box !important;
display: inline-block !important;
word-spacing: normal !important;
vertical-align: top !important;
margin-left:0px !important;
@mazhar266
mazhar266 / cURL.sh
Created April 13, 2013 06:04
Command line cURL for posting data
# for posting data only
curl --data "param1=value1&param2=value2" http://example.com/resource.cgi
# for posting files
curl --form "fileupload=@filename.txt" http://example.com/resource.cgi
.anim {
-webkit-transform: translate3d(0,0,0);
-moz-transform: translate3d(0,0,0);
-ms-transform: translate3d(0,0,0);
-o-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}