This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function character_limiter($str, $n = 500, $end_char = '…') | |
| { | |
| if (strlen($str) < $n) | |
| { | |
| return $str; | |
| } | |
| $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); | |
| if (strlen($str) <= $n) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $file = '/path/to/file.php'; | |
| $info = pathinfo($file); | |
| echo $info['extension']; | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| list($width, $height, $type, $attr) = getimagesize("img.jpg"); | |
| echo $width."<br>".$height."<br>".$type."<br>".$attr."<br>"; | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Insert into database | |
| mysql_query("INSERT INTO my_table (`column1`, `column2`) VALUES ('one', 'two')"); | |
| // Next Get what the auto incremented number was that was inserted | |
| $id = mysql_insert_id(); | |
| // Display it... | |
| echo $id; | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| error_reporting(0); | |
| function toHex($N) { | |
| if ($N==NULL) return "00"; | |
| if ($N==0) return "00"; | |
| $N=max(0,$N); | |
| $N=min($N,255); | |
| $N=round($N); | |
| $string = "0123456789ABCDEF"; | |
| $val = (($N-$N%16)/16); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function human_size ($size) { | |
| if ($size <= 1024) return $size.' Bytes'; | |
| else if ($size <= (1024*1024)) return sprintf('%d KB',(int)($size/1024)); | |
| else if ($size <= (1024*1024*1024)) return sprintf('%.2f MB',($size/(1024*1024))); | |
| else return sprintf('%.2f Gb',($size/(1024*1024*1024))); | |
| } | |
| echo human_size(32768); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function random_string($len=20){ | |
| $randstr = ''; | |
| srand((double)microtime()*1000000); | |
| for($i=0;$i<$len;$i++){ | |
| $n = rand(48,120); | |
| while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96)){ | |
| $n = rand(48,120); | |
| } | |
| $randstr .= chr($n); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| // Let me start off by saying I do not take full credit for this! | |
| // I needed a way to get my traffic's country for Adverts... | |
| // for some reason, json_decode wasn't working, so this is an alternative. | |
| // json_decoder function from PHP.net | |
| // file_get_contents_curl basic data retrieval function | |
| // how to use: | |
| // include('country.php'); | |
| // $userCountry=getTheCountry(); | |
| // output is 2 character country code, US, CA, etc... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once("pcalendar.php"); | |
| $datex = new jDateTime(true, true, 'Asia/Tehran'); | |
| echo $datex->date('Y-m-d',time()); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Day j Day of the Month, No Leading Zeros 1 - 31 | |
| Day d Day of the Month, 2 Digits, Leading Zeros 01 - 31 | |
| Day D Day of the Week, First 3 Letters Mon - Sun | |
| Day l (lowercase 'L') Day of the Week Sunday - Saturday | |
| Day N Numeric Day of the Week 1 (Monday) - 7 (Sunday) | |
| Day w Numeric Day of the Week 0 (Sunday) - 6 (Saturday) | |
| Day S English Suffix For Day of the Month st, nd, rd or th | |
| Day z Day of the Year 0 - 365 | |
| Week W Numeric Week of the Year (Weeks Start on Mon.) 1 - 52 | |
| Month M Textual Representation of a Month, Three Letters Jan - Dec |