Skip to content

Instantly share code, notes, and snippets.

@ScrambledBits
Created June 1, 2012 06:26
Show Gist options
  • Save ScrambledBits/2849521 to your computer and use it in GitHub Desktop.
Save ScrambledBits/2849521 to your computer and use it in GitHub Desktop.
Random PHP snippets
<?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 &copy;" . $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>
@xeoncross
Copy link

You don't need to do date("Y",$time); since date() defaults to the same value as time(). Just do date("Y");.

You don't need to add strip_tags($input, ""), just write it as strip_tags($input) since again, the default is "". Also, you should add htmlspecialchars() since strip_tags() will not protect you from XSS attacks.

@ScrambledBits
Copy link
Author

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