分类:
2011-09-04 21:18:08
1 |
function highlight( $sString , $aWords ) { |
2 |
if (! is_array ( $aWords ) || empty ( $aWords ) || ! is_string ( $sString )) { |
3 |
return false; |
4 |
} |
5 |
|
6 |
$sWords = implode ( '|' , $aWords ); |
7 |
return preg_replace ( '@\b(' . $sWords . ')\b@si' , '$1' , $sString ); |
8 |
} |
01 |
function get_average_readers( $feed_id , $interval = 7){ |
02 |
$today = date ( 'Y-m-d' , strtotime ( "now" )); |
03 |
$ago = date ( 'Y-m-d' , strtotime ( "-" . $interval . " days" )); |
04 |
$feed_url = "" . $feed_id . "&dates=" . $ago . "," . $today ; |
05 |
$ch = curl_init(); |
06 |
curl_setopt( $ch , CURLOPT_RETURNTRANSFER, 1); |
07 |
curl_setopt( $ch , CURLOPT_URL, $feed_url ); |
08 |
$data = curl_exec( $ch ); |
09 |
curl_close( $ch ); |
10 |
$xml = new SimpleXMLElement( $data ); |
11 |
$fb = $xml ->feed->entry[ 'circulation' ]; |
12 |
|
13 |
$nb = 0; |
14 |
foreach ( $xml ->feed->children() as $circ ){ |
15 |
$nb += $circ [ 'circulation' ]; |
16 |
} |
17 |
|
18 |
return round ( $nb / $interval ); |
19 |
} |
01 |
function generatePassword( $length =9, $strength =0) { |
02 |
$vowels = 'aeuy' ; |
03 |
$consonants = 'bdghjmnpqrstvz' ; |
04 |
if ( $strength >= 1) { |
05 |
$consonants .= 'BDGHJLMNPQRSTVWXZ' ; |
06 |
} |
07 |
if ( $strength >= 2) { |
08 |
$vowels .= "AEUY" ; |
09 |
} |
10 |
if ( $strength >= 4) { |
11 |
$consonants .= '23456789' ; |
12 |
} |
13 |
if ( $strength >= 8 ) { |
14 |
$vowels .= '@#$%' ; |
15 |
} |
16 |
|
17 |
$password = '' ; |
18 |
$alt = time() % 2; |
19 |
for ( $i = 0; $i < $length ; $i ++) { |
20 |
if ( $alt == 1) { |
21 |
$password .= $consonants [(rand() % strlen ( $consonants ))]; |
22 |
$alt = 0; |
23 |
} else { |
24 |
$password .= $vowels [(rand() % strlen ( $vowels ))]; |
25 |
$alt = 1; |
26 |
} |
27 |
} |
28 |
return $password ; |
29 |
} |
01 |
header( 'Content-type: text/css' ); |
02 |
ob_start( "compress" ); |
03 |
function compress( $buffer ) { |
04 |
/* remove comments */ |
05 |
$buffer = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!' , '' , $buffer ); |
06 |
/* remove tabs, spaces, newlines, etc. */ |
07 |
$buffer = str_replace ( array ( "\r\n" , "\r" , "\n" , "\t" , ' ' , ' ' , ' ' ), '' , $buffer ); |
08 |
return $buffer ; |
09 |
} |
10 |
|
11 |
/* your css files */ |
12 |
include ( 'master.css' ); |
13 |
include ( 'typography.css' ); |
14 |
include ( 'grid.css' ); |
15 |
include ( 'print.css' ); |
16 |
include ( 'handheld.css' ); |
17 |
|
18 |
ob_end_flush(); |
1 |
function getTinyUrl( $url ) { |
2 |
return file_get_contents ( "" . $url ); |
3 |
} |
01 |
function age( $date ){ |
02 |
$year_diff = '' ; |
03 |
$time = strtotime ( $date ); |
04 |
if (FALSE === $time ){ |
05 |
return '' ; |
06 |
} |
07 |
|
08 |
$date = date ( 'Y-m-d' , $time ); |
09 |
list( $year , $month , $day ) = explode ( "-" , $date ); |
10 |
$year_diff = date ( "Y" ) – $year ; |
11 |
$month_diff = date ( "m" ) – $month ; |
12 |
$day_diff = date ( "d" ) – $day ; |
13 |
if ( $day_diff < 0 || $month_diff < 0) $year_diff –; |
14 |
|
15 |
return $year_diff ; |
16 |
} |
01 |
//Create a variable for start time |
02 |
$time_start = microtime(true); |
03 |
|
04 |
// Place your PHP/HTML/JavaScript/CSS/Etc. Here |
05 |
|
06 |
//Create a variable for end time |
07 |
$time_end = microtime(true); |
08 |
//Subtract the two times to get seconds |
09 |
$time = $time_end - $time_start ; |
10 |
|
11 |
echo 'Script took ' . $time . ' seconds to execute' ; |
01 |
function maintenance( $mode = FALSE){ |
02 |
if ( $mode ){ |
03 |
if ( basename ( $_SERVER [ 'SCRIPT_FILENAME' ]) != 'maintenance.php' ){ |
04 |
header( "Location: " ); |
05 |
exit ; |
06 |
} |
07 |
} else { |
08 |
if ( basename ( $_SERVER [ 'SCRIPT_FILENAME' ]) == 'maintenance.php' ){ |
09 |
header( "Location: " ); |
10 |
exit ; |
11 |
} |
12 |
} |
13 |
} |
1 |
rel= "stylesheet" type= "text/css" /&glt; |
01 |
function make_ranked( $rank ) { |
02 |
$last = substr ( $rank , -1 ); |
03 |
$seclast = substr ( $rank , -2, -1 ); |
04 |
if ( $last > 3 || $last == 0 ) $ext = 'th' ; |
05 |
else if ( $last == 3 ) $ext = 'rd' ; |
06 |
else if ( $last == 2 ) $ext = 'nd' ; |
07 |
else $ext = 'st' ; |
08 |
|
09 |
if ( $last == 1 && $seclast == 1) $ext = 'th' ; |
10 |
if ( $last == 2 && $seclast == 1) $ext = 'th' ; |
11 |
if ( $last == 3 && $seclast == 1) $ext = 'th' ; |
12 |
|
13 |
return $rank . $ext ; |
14 |
} |