Skip to content
Advertisement

Tag: php

How do I find the MIME type of a file with PHP?

I have an index.php file which has to process many different file types. How do I guess the filetype based on the REQUEST_URI? If I request http://site/image.jpg, and all requests redirect through index.php, which looks like this How would I make that work correctly? Should I test based on the extension of the file requested, or is there a way

When and why should $_REQUEST be used instead of $_GET / $_POST / $_COOKIE?

Question in the title. And what happens when all 3 of $_GET[foo], $_POST[foo] and $_COOKIE[foo] exist? Which one of them gets included to $_REQUEST? Answer I’d say never. If I wanted something to be set via the various methods, I’d code for each of them to remind myself that I’d done it that way – otherwise you might end up

Does PHP class property scope overridden by passing as reference?

In PHP, if you return a reference to a protected/private property to a class outside the scope of the property does the reference override the scope? e.g. Is this correct and is the array bar being passed by reference? Answer Well, your sample code is not PHP, but yes, if you return a reference to a protected variable, you can

How do I use PHP to get the current year?

I want to put a copyright notice in the footer of a web site, but I think it’s incredibly tacky for the year to be outdated. How would I make the year update automatically with PHP 4 or PHP 5? Answer You can use either date or strftime. In this case I’d say it doesn’t matter as a year is a year,

Compile a PHP script in Linux

I know PHP scripts don’t actually compile until they are run. However, say I want to create a small simple program and compile it to a binary without requiring the PHP binary. How could I do this? I’ve seen a few IDE’s out there that would do this, but either they are all for windows or the Linux versions don’t

PHP equivalent of .NET/Java’s toString()

How do I convert the value of a PHP variable to string? I was looking for something better than concatenating with an empty string: Like the ToString() method in Java or .NET. Answer You can use the casting operators: There are more details for string casting and conversion in the Strings section of the PHP manual, including special handling for

Advertisement