PHP Sample Code Collection — Basics, Database, HTTP Requests, Email, Technical Utilities, and More
PHP Samples
- Basic
-
How to Convert Full-width, Half-width, Katakana, and Hiragana in PHP|How to Use mb_convert_kana and Complete Option List
This guide explains how to freely convert full-width, half-width, katakana, and hiragana characters in PHP using the mb_convert_kana function. It also includes practical examples and a complete explanation of each option.
-
Handling Dates and Times in PHP — Sample Source Code
A sample-based guide explaining how to work with dates and times in PHP, including year, month, day, hour, minute, second, and time zones.
-
How to Handle JSON in PHP|Using json_encode and json_decode Safely and Effectively
A practical guide to handling JSON in PHP, explaining how to use json_encode and json_decode. Covers converting arrays and objects, common pitfalls such as garbled characters or unexpected null values, and important usage tips.
-
How to Convert Images to WebP in PHP|Using imagewebp with JPG and PNG Files
A practical guide on converting JPG and PNG images to WebP format in PHP. Covers how to use imagecreatefromjpeg, imagecreatefrompng, and imagewebp, including quality settings, transparency handling, and saving WebP files with clear sample code.
- DataBase
-
Connecting to MariaDB with PHP PDO | How to Insert, Update, Delete, and Retrieve Data
A guide to connecting to MariaDB (MySQL) using PHP PDO and performing data insertion, updates, deletions, and retrieval. Includes secure SQL execution using prepare and execute.
- http,https Request
-
HTTP and HTTPS Requests in PHP Using file_get_contents and cURL — Sample Source Code Collection
A sample-based guide explaining how to perform HTTP and HTTPS requests in PHP using file_get_contents and cURL.
- Sending EMails
-
Sending Japanese Emails (JIS or UTF‑8) with PHP’s mb_send_mail
A source‑code based guide explaining how to send Japanese emails in ISO‑2022‑JP or UTF‑8 using PHP’s mb_send_mail function.
-
How to Send HTML Emails in PHP|Understanding Multipart Structure and Embedded Images
A concise guide to sending HTML‑formatted emails in PHP, covering multipart message structure, Content‑Type settings, embedded images, and key points to watch out for.
- Technical
-
Creating UTF‑8 CSV Files in PHP That Open Correctly in Excel|Handling Garbled Text, Double Quotes, Leading Zeros, and Line Breaks
A detailed guide on how to generate UTF‑8 CSV files in PHP that open correctly in Excel. Learn how to prevent character corruption by adding a BOM, properly escape double quotes, preserve numbers with leading zeros, and output line breaks inside cells, with complete code examples.
-
How to Generate PDF Files with TCPDF in PHP|Examples with Japanese Text, Images, and Shapes
A guide to generating PDF files in PHP using the TCPDF library. Includes examples for handling Japanese text, images, shapes, lines, headers, margins, and more.
-
Preventing Multiple PHP Script Executions in CRON — A Smart and Reliable Approach
A safe and reliable method to prevent multiple PHP script executions during scheduled CRON runs. Uses pgrep and preg_quote to ensure stable and conflict‑free operation
- Source Code
-
Server Monitoring with PHP and Shell Scripts — Automated Checks Using CRON
An explanation of how to monitor servers using PHP’s shell_exec along with tools like top and vmstat. Includes scripts that perform periodic checks via CRON to detect zombie processes and high load.
-
Image‑based CAPTCHA in PHP (Hiragana, Numbers, Alphabet) — Source Code Included
This page provides PHP source code for implementing image‑based CAPTCHA for bot protection, including hiragana, numeric, and alphabet verification
