Skip to content

Instantly share code, notes, and snippets.

View daveh's full-sized avatar

Dave Hollingworth daveh

View GitHub Profile
@daveh
daveh / index.php
Created August 14, 2022 11:23
Show all errors in PHP (code to accompany https://youtube.com/shorts/K4TMD0mLOJY)
<?php
ini_set("display_errors", "1");
ini_set("display_startup_errors", "1");
error_reporting(E_ALL);
@daveh
daveh / form.html
Last active June 4, 2024 05:26
Send email with PHP (code to accompany https://youtu.be/fIYyemqKR58)
<!DOCTYPE html>
<html>
<head>
<title>Contact</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
</head>
<body>
<h1>Contact</h1>
@daveh
daveh / form.html
Last active May 3, 2024 11:17
Generate a PDF with PHP (code to accompany https://youtu.be/XGS732DLtDc)
<!DOCTYPE html>
<html>
<head>
<title>PDF Example</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
</head>
<body>
<h1>Example</h1>
@daveh
daveh / form.html
Last active May 11, 2024 11:23
HTML to MySQL using PHP (code to accompany https://youtu.be/Y9yE98etanU)
<!DOCTYPE html>
<html>
<head>
<title>Contact</title>
<meta charset="UTF-8">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.min.css">
</head>
<body>
@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
)
{}
}
@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 / 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 / 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 / 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 / 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);