Skip to main content

23 posts tagged with "PHP"

PHP Programming Language and Runtime

View All Tags

How to Decode Base64 in PHP with base64_decode

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

Base64 turns bytes into plain text so they can travel in JSON, URLs or environment variables. PHP's base64_decode turns it back, and with its second argument set to true it refuses anything that isn't valid base64 instead of quietly skipping it.

How to Call a Static Method in PHP

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

Some methods don't need an object at all: converting a temperature only needs the number you pass in. Declare such a method static and call it on the class itself, Temperature::toFahrenheit(24), with no new first.

How to Catch an Exception in PHP

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

When code hits a problem it can't handle, it throws an exception, and the script stops unless something catches it. Wrapping the call in try and naming the exception's class in catch lets you handle the failure you expected and carry on.

How to Print Output in PHP with echo

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

echo is how a PHP script writes text: to the terminal for a command-line script, to the page for a web request. It prints exactly what you give it, with no spaces or new lines added, so you place those yourself.

How to Put Variables in a String in PHP

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

In a double-quoted PHP string, variables are replaced by their values: "You ordered $quantity items". Curly braces mark exactly where a variable ends, which you need for array values and for text written right after a variable. Single-quoted strings never replace anything.