THE CODE
Programming
Programming is most useful when a small, clear example helps solve a real problem. This section will grow with working PHP and JavaScript examples.

How to Get the Current Page URL with PHP
Separate the requested address from the canonical address and avoid making your public hostname depend on untrusted request headers.
Explore
Tic-Tac-Toe AI with Minimax and Alpha-Beta Pruning
See how a computer can choose a move by searching possible replies, then try the new browser-based teaching demo.
Explore
Common PHP File-Path Problems and How to Fix Them
Understand why a file loads from one page but fails from another, then make the path rules explicit.
Explore
How to Synchronize Scrolling Between Two Elements
Build a bidirectional scroll link that handles different content heights without taking over the visitor’s input.
Explore
How to Extract a Directory Name from a URL in PHP
Separate URL paths from query strings, identify category and article segments, and handle missing or unexpected values.
Explore
Build PHP Recommendations That Exclude the Current Page
Select related pages from a trusted directory, exclude the page being viewed, and handle small categories without duplicate links.
Explore
Replace onmouseover with JavaScript Event Listeners
Move hover behavior out of HTML, avoid child-element flicker, and support keyboard focus alongside pointer interaction.
Explore
How to Pick a Random Item from a PHP Array
Select one entry or several unique entries while handling array keys, empty lists and repeat choices.
Explore
PHP Redirects: How to Use header() Correctly
Send visitors to a new page without output errors, redirect loops or an untrusted destination.
Explore
Read a Text File Line by Line
Choose between file() and fgets(), with practical path and blank-line checks.
Explore
Build an Item of the Day
Match each physical line in a file to a calendar day with a defined time zone.
Explore
Replace Inline onclick
Use addEventListener() with accessible buttons, event options and cleanup.
Explore PRACTICAL TOOLURL Encoder & Decoder
See how URL components are encoded and decoded in the browser.
Explore PRACTICAL TOOLMeta Description Counter
Measure text length as you prepare page metadata.
Explore