Created
June 1, 2012 06:26
-
-
Save ScrambledBits/2849521 to your computer and use it in GitHub Desktop.
Random PHP snippets
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 | |
// Strip HTML characters from a given text. | |
$text = htmlspecialchars(strip_tags($input)); | |
// Remove links from a string | |
$string = preg_replace('/\b(https?|ftp|file:(\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $string); | |
//detect iPhone/iPod/iPad | |
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod')) { | |
header('Location: http://yoursite.com/iphone'); | |
exit(); | |
} | |
//update copyright notice | |
$year= date("Y"); | |
//This line formats it to display just the year | |
echo "Copyright ©" . $year . " YOUR-SITE-NAME | All Rights Reserved"; | |
//this line prints out the copyright date range | |
?> | |
<html> | |
<head> | |
<!-- Set width for iPhone Screen --> | |
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"> | |
<!-- Set icon for iPhone webapp --> | |
<rel="apple-touch-icon" href="images/template/engage.png"/> | |
<script language="javascript"> | |
window.onload = function initialLoad() { | |
updateOrientation(); | |
} | |
function updateOrientation(){ | |
var contentType = "show_"; | |
switch(window.orientation){ | |
case 0: | |
contentType += "normal"; | |
break; | |
case -90: | |
contentType += "right"; | |
break; | |
case 90: | |
contentType += "left"; | |
break; | |
case 180: | |
contentType += "flipped"; | |
break; | |
} | |
document.getElementById("page_wrapper").setAttribute("class", contentType); | |
} | |
</script> | |
</head> | |
<body> | |
<!-- iPhone-only links --> | |
<a href="tel:12345678900">Call me</a> | |
<a href="sms:12345678900">Send me a text</a></body> | |
</html> |
Thank you, I have modified the snippets. I had not seen it that way...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need to do
date("Y",$time);
sincedate()
defaults to the same value astime()
. Just dodate("Y");
.You don't need to add
strip_tags($input, "")
, just write it asstrip_tags($input)
since again, the default is "". Also, you should addhtmlspecialchars()
sincestrip_tags()
will not protect you from XSS attacks.