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
| <script type="text/javascript"> | |
| /* Source: http://www.apphp.com/index.php?snippet=javascript-email-validation */ | |
| function check_email(email){ | |
| var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; | |
| if(reg.test(email)){ | |
| return true; | |
| }else{ | |
| return false; | |
| } | |
| } |
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
| <!-- Sample #1: form button --> | |
| /* Source: http://www.apphp.com/index.php?snippet=javascript-close-window */ | |
| <form> | |
| <input type=button value="Close This Window" onclick="javascript:window.close();"> | |
| </form> | |
| <!-- Sample #2: text link --> | |
| <a href="javascript:window.close();">Click Here to Close Window</a> | |
| <!-- Sample #3: close window after a given number of seconds --> |
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
| <script type="text/javascript"> | |
| /* Source: http://www.apphp.com/index.php?snippet=javascript-pass-parameters-in-setinterval */ | |
| // sample #1 | |
| setInterval('alert_function(1)', 1500); | |
| // sample #2 | |
| setInterval(function(){ alert_function(10); }, 1500); | |
| // user's alert function | |
| function alert_function(val){ |
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
| <script type="text/javascript"> | |
| /* Source: http://www.apphp.com/index.php?snippet=javascript-toggle-elements */ | |
| function toggle(id, id2){ | |
| var toggle_one = document.getElementById(id); | |
| var toggle_two = document.getElementById(id2); | |
| if(toggle_one.style.display == "block"){ | |
| toggle_one.style.display = "none"; | |
| toggle_two.innerHTML = "Show"; | |
| }else{ | |
| toggle_one.style.display = "block"; |
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 | |
| /* Source: http://www.apphp.com/index.php?snippet=php-remove-duplicates-in-array */ | |
| $input = array("a"=>"apple", "pear", "b"=>"apple", "orange", "avocado", "banana"); | |
| print_r($input); | |
| $result = array_unique($input); | |
| print_r($result); | |
| ?> |
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 | |
| /* Source: http://www.apphp.com/index.php?snippet=php-parsing-xml-file */ | |
| // this is a sample xml string | |
| $xml_string="<?xml version='1.0'?> | |
| <text> | |
| <article id='Article1'> | |
| <title>Title 1</title> | |
| <content>..text here..</content> | |
| </article> | |
| <article id='Article2'> |
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 | |
| /* Source: http://www.apphp.com/index.php?snippet=php-download-file-with-speed-limit */ | |
| /* set here a limit of downloading rate (e.g. 10.20 Kb/s) */ | |
| $download_rate = 10.20; | |
| $download_file = 'download-file.zip'; | |
| $target_file = 'target-file.zip'; | |
| if(file_exists($download_file)){ | |
| /* headers */ |
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 | |
| /* Source: http://www.apphp.com/index.php?snippet=php-list-directory-contents */ | |
| function list_directory_content($dir){ | |
| if(is_dir($dir)){ | |
| if($handle = opendir($dir)){ | |
| while(($file = readdir($handle)) !== false){ | |
| if($file != '.' && $file != '..' && $file != '.htaccess'){ | |
| echo '<a target="_blank" href="'.$dir.$file.'">'.$file.'</a><br>'."\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 | |
| /* Source: http://www.apphp.com/index.php?snippet=php-get-file-extension */ | |
| function get_file_extension($file_name) | |
| { | |
| /* may contain multiple dots */ | |
| $string_parts = explode('.', $file_name); | |
| $extension = $string_parts[count($string_parts) - 1]; | |
| $extension = strtolower($extension); | |
| return $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
| <style type="text/css"> | |
| /* Source: http://www.apphp.com/index.php?snippet=php-get-remote-ip-address */ | |
| p.first { margin-top: 0 !important; margin-left: 0 !important; } | |
| p.last { margin-bottom: 0 !important; margin-right: 0 !important; } | |
| /* or */ | |
| div#articles p:first-child { border:1px solid #c1c13a; } | |
| div#articles p:last-child { border:1px solid #3ac13a; } | |
| /* or */ | |
| div#articles > :first-child { text-align:left; } |