This file contains 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 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-remote-ip-address */ | |
$to = 'myfriend@gmail.com'; | |
$subject = 'Test Email'; | |
$body = 'Body of your message here. You can use HTML tags also, e.g. <br><b>Bold</b>'; | |
$headers = 'From: John Smith'."\r\n"; | |
$headers .= 'Reply-To: from@email.me'."\r\n"; | |
$headers .= 'Return-Path: from@email.me'."\r\n"; | |
$headers .= 'X-Mailer: PHP5'."\n"; | |
$headers .= 'MIME-Version: 1.0'."\n"; |
This file contains 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: redirect errors to html files | |
ErrorDocument 400 /400.html | |
ErrorDocument 401 /401.html | |
ErrorDocument 403 /403.html | |
ErrorDocument 404 /404.html | |
ErrorDocument 405 /405.html | |
ErrorDocument 408 /408.html | |
ErrorDocument 414 /414.html | |
ErrorDocument 500 /500.html | |
ErrorDocument 502 /502.html |
This file contains 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=css-center-site-content */ | |
/* Center your website horizontally */ | |
.wrapper{ | |
width:960px; | |
display:table; | |
margin:auto; | |
} | |
/* Center certain content vertically */ |
This file contains 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
<!-- http://www.apphp.com/index.php?page=html_snippets --> | |
<!-- Grab Google CDN's jQuery and load local version if necessary --> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
<script type="text/javascript">!window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')</script> |
This file contains 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=php-get-country-by-ip | |
function getLocationInfoByIp(){ | |
$client = @$_SERVER['HTTP_CLIENT_IP']; | |
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; | |
$remote = @$_SERVER['REMOTE_ADDR']; | |
$result = array('country'=>'', 'city'=>''); | |
if(filter_var($client, FILTER_VALIDATE_IP)){ | |
$ip = $client; | |
}elseif(filter_var($forward, FILTER_VALIDATE_IP)){ | |
$ip = $forward; |
This file contains 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=javascript-focus-on-load --> | |
<!-- This part goes into your body tag --> | |
<body OnLoad="document.myform.user.focus();"> | |
<!-- You you just use the name of the form and field name within your form --> | |
<form name="myform"> | |
Name: <input type="text" name="user" size="10"> | |
Email: <input type="text" name="email" size="10"> | |
</form> | |
This file contains 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 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-5-media-code --> | |
<video poster="images/preview.png" width="800" height="600" controls="controls" preload="none"> | |
<source src="media/my_video.mp4" type="video/mp4"></source> | |
<source src="media/my_video.webm" type="video/webm"></source> | |
<source src="media/my_video.ogg" type="video/ogg"></source> | |
</video> | |
<audio controls="controls" preload="none"> | |
<source src="audio/my_music.ogg" type="audio/ogg"> | |
<source src="audio/my_music.mp3" type="audio/mpeg"> | |
</audio> |
NewerOlder