Questions

PHP questions

Choose a question page, learn the concept, then test your understanding with a quiz.

How to Fix the "Headers Already Sent" Error in PHP

Learn why PHP shows "Headers already sent" and how to fix it when using header() or setcookie() with clear examples.

phphttp-headers

How to Get Raw SQL from Laravel Query Builder

Learn how to view the raw SQL generated by Laravel's query builder, including toSql(), bindings, and common debugging patterns.

phpsqllaraveleloquent

How to Get a File Extension in PHP

Learn the best way to get a file extension in PHP, including pathinfo(), edge cases, examples, and common mistakes beginners make.

phpfile-extension

How to Get a YouTube Video Thumbnail in PHP Using the YouTube API

Learn how to get a YouTube video thumbnail from a YouTube URL in PHP using the YouTube Data API and simple thumbnail URLs.

phpcurlyoutubeyoutube-api

How to Get the Client IP Address in PHP

Learn how to get a client IP address in PHP, when to use REMOTE_ADDR, and how to safely handle proxies and logging.

phpenvironment-variablesip-address

How to Get the Current Date and Time in PHP

Learn how to get the current date and time in PHP using date(), time(), and DateTime with clear examples and common mistakes.

phpdatetime

How to Get the Current Year in PHP for Dynamic Copyright Footers

Learn how to get the current year in PHP and use it in a dynamic copyright footer that updates automatically every year.

phpdate

How to Get the First Element of an Array in PHP

Learn how to get the first element of a PHP array without using array_shift or passing by reference, with examples and common pitfalls.

phparrays

How to Get the First Key of an Array in PHP

Learn how to get the first key of an array in PHP, including associative arrays, older approaches, and common mistakes to avoid.

phparrays

How to Get the Full Current URL in PHP

Learn how to get the full current URL in PHP, including rewritten paths, query strings, and HTTPS, with practical examples and common pitfalls.

phpurl

How to Hash Passwords with bcrypt in PHP

Learn what bcrypt is in PHP, how password_hash and password_verify work, and the correct way to store passwords securely.

phppasswordscryptographypassword-protection

How to Parse and Process HTML/XML in PHP

Learn how to parse HTML and XML in PHP using DOMDocument, XPath, and SimpleXML to extract data safely and clearly.

phphtmlxmlxml-parsing

How to Pass Variables from PHP to JavaScript Safely

Learn how to pass PHP variables to JavaScript safely using json_encode, data attributes, and script blocks with practical examples.

phpjavascript

How to Prevent SQL Injection in PHP

Learn how to prevent SQL injection in PHP using prepared statements, parameter binding, input validation, and safe database APIs.

phpmysqlsqlsecurity

How to Redirect in PHP with the header() Function

Learn how to redirect users in PHP using header(), including syntax, login protection, common mistakes, and real examples.

phphttp-redirecthttp-status-code-301

How to Remove Empty Array Elements in PHP

Learn how to remove empty strings from PHP arrays, why unset() inside foreach fails, and the best ways to clean user input safely.

phparraysstring

How to Remove Spaces from a String in PHP

Learn how to remove spaces from a string in PHP using str_replace, regex, and trim, with examples, mistakes, and practical use cases.

phpstringspaces

How to Remove the Last Character from a String in JavaScript

Learn how to remove a trailing character from a delimited string in JavaScript using slice, regex, and safe checks.

phpcsvdelimitertruncate

How to Return JSON from a PHP Script

Learn how to return JSON from PHP correctly using json_encode, proper headers, and practical examples for APIs and AJAX responses.

phpjsonheader

How to Sanitize User Input in PHP for SQL Injection and XSS

Learn how to sanitize and validate user input in PHP to prevent SQL injection and XSS while safely allowing selected HTML tags.

phpsecurityxsssql-injection

Page 2 of 4 - 62 questions