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 current_season() { | |
| // Locate the icons | |
| $icons = array( | |
| "spring" => "images_spring/", | |
| "summer" => "images_summer/", | |
| "autumn" => "images_autumn/", | |
| "winter" => "images_winter/" | |
| ); |
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 | |
| $execution_time = microtime(); # Start counting | |
| # Your code | |
| $execution_time = microtime() - $execution_time; | |
| $execution_time = sprintf('It took %.5f sec', $execution_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
| <?php | |
| function readableArray($elements, $delimiter = ', ', $finalDelimiter = ' and ') { | |
| $lastElement = array_pop($elements); | |
| return join($delimiter, $elements) . $finalDelimiter . $lastElement; | |
| } | |
| ?> |
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 passStr($len, $set = "") { | |
| $gen = ""; | |
| for($i=0;$i<$len;$i++) { | |
| $set = str_shuffle($set); | |
| $gen .= $set[0]; | |
| } | |
| return $gen; | |
| } |
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 file_newname($path, $filename){ | |
| if ($pos = strrpos($filename, '.')) { | |
| $name = substr($filename, 0, $pos); | |
| $ext = substr($filename, $pos); | |
| } else { | |
| $name = $filename; | |
| } | |
| $newpath = $path.'/'.$filename; |
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
| <!-- source: http://www.apphp.com/index.php?snippet=html-multiple-file-input --> | |
| <form action="upload.php" method="post" enctype="multipart/form-data"> | |
| <input name="upload_files[]" type="file" multiple> | |
| <input type="submit" value="Upload"> | |
| </form> | |
| <?php | |
| // PHP code | |
| that shows how to loop through the data as an array | |
| foreach($_FILES["upload_files"]["name"] as $file){ |
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 | |
| // yes, the argument list can be empty | |
| function foo() { | |
| // returns an array of all passed arguments | |
| $args = func_get_args(); | |
| foreach ($args as $k => $v) { | |
| echo "arg".($k+1).": $v\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 | |
| // © 2012-2013, [ Abstract Codify ] Abstractcodify.com All Rights Reserved. | |
| $realm = 'Restricted area'; | |
| //user => password | |
| $users = array('admin' => 'mypass', 'guest' => 'guest'); | |
| if (empty($_SERVER['PHP_AUTH_DIGEST'])) { | |
| header('HTTP/1.1 401 Unauthorized'); |
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 | |
| $dir = "./uploads/post-templates"; | |
| $files = scandir($dir); | |
| while($files[0] == "." || $files[0] == "..") { | |
| array_shift($files); | |
| } | |
| ?> |
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 | |
| //Define directory for files listing | |
| //original example | |
| //$files = glob('/path/to/dir/*.xml'); | |
| $files = glob('*.php'); | |
| //to limit what is displayed you can use a diff listing: | |
| //$files = array_diff($files, array('index.php','opendb.php')); | |
| foreach ($files as $value) { | |
| echo "<a href=http://changetoyoursite/$value>".$value."</a><br>"; |