Skip to content

Instantly share code, notes, and snippets.

View petk's full-sized avatar

Peter Kokot petk

View GitHub Profile
@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";
}
@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 / 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 / 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 / .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 / README.md
Last active October 13, 2024 00:23
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 / 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: