by
Janeth Kent
Date: 11-04-2013
Here’s a mini list of useful PHP code snippets that we find using on a weekly basis. You could use these as is or expand them as part of other applications or add them to a php class.
Adjust server time
Useful if you have a server in a different timezone, like us... You can fix funny things happen when you add the time to a MySQL database, by adding or subtracting hours as in the example below.
$now = date('Y-m-d-G');
$now = strftime("%Y-%m-%d-%H", strtotime("$now -8 hours"));
Convert HEX value to RBG
function hextorgb($hexvalue){
if($hexvalue[0] == '#') {
$hexvalue = substr( $hexvalue, 1);
if(strlen( $hexvalue ) == 6){
list($r, $g, $b) = array($hexvalue[0] .$hexvalue[1], $hexvalue[2] . $hexvalue[3], $hexvalue[4] .$hexvalue[5]);
}elseif (strlen($hexvalue) == 3) {
list($r,$g,$b) = array($hexvalue[0] .$hexvalue[0], $hexvalue[1] . $hexvalue[1], $hexvalue[2] .$hexvalue[2]);
return array('R' => $r, 'G' => $g, 'B' => $b);
$rgb = hextorgb('#fff000');
print_r($rgb);
Display a users Gravatar image
function url_to_link($text){
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
// Check if there is a url in the string
if (preg_match_all($reg_exUrl, $text, $url)) {
$position = strpos($text,' '.$v)+1;
$text = substr_replace($text,'',$position, strlen($v));
$text = substr_replace($text,''.$v.'',$position ,0);
// if no urls in the text just return the text
$string = 'This is a string of text and we have a link: http://ma-no.org we also have another link http://google.com';
echo url_to_link($string);
Parse JSON in PHP
$json='{"id":0,"name":"Silvia","surname":"Salvietta","Website":"http://ma-no.org"} ';
$array=json_decode($json);
echo $array->name;
by
Janeth Kent Date:
11-04-2013
hits :
3013
Latest news from Hi-Tech world
Some time ago we wrote about how to Import one JS file into another in the plain JS, those techniques described were quite old and in the modern era javascript…
As the digital landscape continues to evolve, ecommerce has become an essential part of businesses worldwide. Entrepreneurs, small businesses, and even established enterprises are seeking robust and costeffective solutions to…
The Robots.txt file serves to give information to Googlebot and other robots that crawl the Internet about the pages and files that should be indexed on our website. Although it…
There is a new standard HTML attribute that can be used in conjunction with IMG called SRCSET. It is new and important as it allows webmasters to display different images…
JWT tokens are a standard used to create application access tokens, enabling user authentication in web applications. Specifically, it follows the RFC 7519 standard.
What is a JWT token
A JWT token…
In this short tutorial we are going to see how you can generate a new SSH key and add it to GitHub, so you can access your private repositories and…
Let's continue with the 2nd part of our article in which we try to give you some advice on how to safely and securely explore the dark web.
Let's restart from…
The dark web can be a pretty dangerous place if you don't take the right precautions. You can stay relatively safe with a good antivirus and a decent VPN. However,…
The internet has transformed the way that people live their lives. You can access a wealth of knowledge from a device that fits in your hand. Yes, it’s used for…
Cyber-violence, i.e. the digital dimension of violence that mainly affects women and is closely linked to the violence that occurs in the 'real world', is a growing phenomenon that is…
In recent years, the digital advertising industry has been undergoing significant transformations. One of the most impactful changes is the impending demise of third-party cookies, which could potentially diminish marketing…
The traditional concept of the office has undergone a substantial transformation in recent years. With advancements in technology and changes in work culture, more professionals are embracing remote work options,…
PuTTy is an emulator for the terminal. It allows you to log into another computer that can be on the same network or accessed via the internet. The basic program…
In this article we will talk about Privacy Policy statements, how you can write one and implement it on your page.
Why did it pop up?
These days when we browse on…
APIs serve as intermediaries between software, allowing them to communicate with each other and perform various functions like data sharing or processing. APIs provide the protocols, definitions, tools, and other…
PHP never ceases to surprise me with its built-in capabilities. These are a few of the functions I find most fascinating.
1. Levenshtein
This function uses the Levenshtein algorithm to calculate the…
If you are one of the 2.5 million sellers on Amazon, you’ll know that the platform has incredible potential for profits. However you’ll also know the competition is fierce and…
There are many people today who only use the following for design purposes Canva as it is a really popular software and website and there is no denying that it…
We have already written several articles about the artificial intelligence that is revolutionising the world, but this time we will talk about how it can help you with everyday tasks…
The best and most amazing Alexa Hacks you should know about
Alexa, Amazon's talking Artificial Intelligence contained in the Echo, can entertain you and your family if you know the right…