Skip to content

Instantly share code, notes, and snippets.

View petk's full-sized avatar
🐘
PHPing

Peter Kokot petk

🐘
PHPing
View GitHub Profile
@petk
petk / README.md
Last active July 3, 2022 03:56
Habit tracker

Habits tracking

Habits tracking is a simple and powerful way to track your daily habits to either improve something in your life or to break some destructive habit.

Templates

Templates are available for download in different sizes:

@petk
petk / README.md
Last active May 16, 2023 17:08
Testing for types, empty() and isset() in PHP

Testing for types, empty() and isset() in PHP

Many times you might want to check if some variable has been set and it holds a non-falsy value.

With PHP loose typing:

if (isset($variable) && !empty($variable)) {
    // ...
@petk
petk / .editorconfig
Last active October 19, 2019 20:28
EditorConfig template
# https://editorconfig.org/
root = true
[*]
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
end_of_line = lf
indent_size = 4
@petk
petk / demo.php
Created May 10, 2018 16:31
PHP example of DateInterval difference
<?php
function getDiff($start, $end)
{
$start = explode(':', $start);
$end = explode(':', $end);
$start = new DateInterval('PT'.$start[0].'H'.$start[1].'M'.$start[2].'S');
$end = new DateInterval('PT'.$end[0].'H'.$end[1].'M'.$end[2].'S');
@petk
petk / form.php
Last active February 26, 2018 20:28
Uploading a file with PHP https://php.earth/docs/security/uploading
<form method="post" enctype="multipart/form-data" action="upload.php">
File: <input type="file" name="file">
<input type="submit">
</form>
@petk
petk / Mailer.php
Created June 26, 2015 12:27
Using PHPMailer
<?php
// this file is inside src folder
namespace PHPWorldWide;
use PHPMailer;
class Mailer
{
@petk
petk / youtubeChecker.php
Created June 23, 2015 20:55
Check if youtube video exists
<?php
$headers = get_headers('http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=nonexistingid');
if (!strpos($headers[0], '200')) {
echo "The YouTube video you entered does not exist";
}
<?php
$count=0;
$url="http://php.net/iterator_to_array";
$html = file_get_contents($url);
$dom = new DOMDocument;
$dom->loadHTML($html);
//$dom->preserveWhiteSpace = false;
$images = $dom->getElementsByTagName('img');
$array = [];
foreach($images as $image){
@petk
petk / nginx.conf
Last active August 29, 2015 14:19
Nginx PHP config sample
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name server_domain_name_or_IP;
location / {
@petk
petk / index.html
Created April 1, 2015 05:07
Symfony 2.6 PHP Metrics report
This file has been truncated, but you can view the full file.
<html>
<head>
<title>PhpMetrics report - by Jean-François Lépine</title>
<meta charset="utf-8">
<link href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFA+LP9QPiz/UD4s/1A+LP9QPiz/UD4s/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUD4s/1A+LP9QPiz/UD4s/1A+LP9QPiz/UD4s/1A+LP9QPiz/UD4s/wAAAAAAAAAAAAAAAAAAAAAAAAAAUD4s/1A+LP9QPiz/UD4s/1A+LP9QPiz/UD4s/wC6eP8sdU7/ALp4/1A+LP9QPiz/AAAAAAAAAAAAAAAAUD4s/1A+LP9QPiz/UD4s/1A+LP9QPiz/UD4s/wC6eP9QPiz/SUgy/wC6eP9LRTD/ALp4/1A+LP8AAAAAAAAAAFA+LP9QPiz/UD4s/1A+LP9QPiz/UD4s/wC6eP89Wz3/ALp4/wCz9P8As/T/UD4s/wC6eP9QPiz/AAAAAFA+LP9QPiz/UD4s/1A+LP9QPiz/TkAt/1A+LP8Aunj/OGJC/wCz9P8As/T/ALP0/xSbZf9QPiz/UD4s/1A+LP9QPiz/UD4s/1A+LP9QPiz/ALp4/1A+LP8Aunj/ALp4/wui2P9QPiz/Cabd/wevcf8Aunj/UD4s/1A+LP9QPiz/UD4s/1A+LP9QPiz/TUMv/wC6eP8Aunj/ALp4/wC6eP8Aunj/ALp4/wynbP9QPiz/K3dP/zZmRP9QPiz/UD4s/1A+LP9QPiz/ALp4/wC6eP8Aunj/TEQw/xqSX/8As/T/SEoz/wC6eP8BuHf/ALP0/wC6eP8Aunj/C6ht/1A+LP9QPiz/OWFC/wC6eP8Aunj/ALp4/01