Skip to content

Instantly share code, notes, and snippets.

View daveh's full-sized avatar

Dave Hollingworth daveh

View GitHub Profile
@daveh
daveh / form.html
Created August 4, 2020 17:30
Handling unchecked checkboxes in PHP: the hidden field trick (code to accompany https://youtu.be/5WKL9QJdc_0)
<!DOCTYPE html>
<html>
<head>
<title>Submitting checkboxes</title>
</head>
<body>
<h1>Submitting checkboxes</h1>
<form method="post" action="handle_form.php">
@daveh
daveh / User.php
Created August 24, 2020 12:30
The difference between use and require in PHP (code to accompany https://youtu.be/aP8iT32Hw-g)
<?php
namespace App;
class User
{
}
@daveh
daveh / index.php
Created October 9, 2020 18:40
Single quotes vs double quotes in PHP (code to accompany https://youtu.be/mkEAx5u-paU)
// Single-quoted strings
echo 'Welcome';
echo '$3,000';
echo '4 o\'clock';
echo 'C:\\data';
// Double-quoted strings
echo "C:\\data";
echo "One\nTwo";
@daveh
daveh / markdown.php
Last active September 7, 2022 02:28
Rich-text formatting in PHP: HTML, Markdown, rich-text editors like TinyMCE and doing it securely (code to accompany https://youtu.be/Udgi43MG0a4)
<?php
require "vendor/autoload.php";
$parser = new Parsedown;
?>
<!DOCTYPE html>
<html>
<head>
@daveh
daveh / data.php
Created February 17, 2021 19:28
Passing data from PHP to JavaScript: methods, their pros and cons, and how to implement them (code to accompany https://youtu.be/u4HmQjLvNe8)
<?php
$name = "David \"Dave\" O'Connor";
header('Content-Type: application/json');
echo json_encode($name);
@daveh
daveh / User.php
Created February 27, 2021 21:01
PHP type declarations: make your PHP code easier to read and simpler to use (code to accompany https://youtu.be/Ig0NbYTStxo)
<?php
class User
{
public int $id;
public string $name;
public ?string $surname = null;
@daveh
daveh / form.html
Created March 22, 2021 19:29
Validating and verifying email addresses in PHP (code to accompany https://youtu.be/JvGFlAK2fg4)
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<form method="post" action="validate_email.php">
<label for="email">email</label>
@daveh
daveh / httpd-vhosts.conf
Created May 1, 2021 18:40
How to set up a virtual host in Apache (WAMP, MAMP, XAMPP) (code to accompany https://youtu.be/kRfo5OPUC2M)
<VirtualHost *:80>
DocumentRoot "/www/project1"
ServerName site1.localhost
<Directory "/www/project1">
Require all granted
AllowOverride All
</Directory>
</VirtualHost>
@daveh
daveh / 1-file_get_contents.php
Created August 8, 2021 15:10
How to call APIs from PHP: file_get_contents, cURL, Guzzle and SDKs (code to accompany https://youtu.be/wMyP-q3nPd4)
<?php
$payload = json_encode([
"title" => "Updated title"
]);
$options = [
"http" => [
"method" => "PATCH",
"header" => "Content-type: application/json; charset=UTF-8\r\n" .
@daveh
daveh / attributes.php
Created January 11, 2022 09:10
What's new in PHP 8.0 (code to accompany https://youtu.be/ve9bKHZG47c)
<?php
#[\Attribute(Attribute::TARGET_CLASS)]
class Route
{
public function __construct(
public string $path
)
{}
}