I have a PHP app that creates a CSV file which is forced to download using headers. Here’s the relevant part of the code: What I’d like to do is redirect users to a new page after the file is built and the download prompt is sent. Just adding header(“Location: /newpage”) to the end didn’t work, expectedly, so I’m not
Category: Questions
is_file or file_exists in PHP
I need to check if a file is on HDD at a specified location ($path.$file_name). Which is the difference between is_file() and file_exists() functions and which is better/faster to use in PHP? Answer is_file() will return false if the given path points to a directory. file_exists() will return true if the given path points to a valid file or directory.
Python equivalent of PHP’s compact() and extract()
compact() and extract() are functions in PHP I find tremendously handy. compact() takes a list of names in the symbol table and creates a hashtable with just their values. extract does the opposite. …
PHP equivalent of send and getattr?
If Ruby gets invited to a party and brings: .. and Python gets invited to the same party and brings: .. what does PHP have to bring to the party? Bonus question: If Ruby and Python got jealous of PHP’s party-favors, what English terms would they search for in PHP’s documentation in order to talk about it behind PHP’s back?
PHP “pretty print” HTML (not Tidy)
I’m using the DOM extension in PHP to build some HTML documents, and I want the output to be formatted nicely (with new lines and indentation) so that it’s readable, however, from the many tests I’ve …
Check whether a directory exists in PHP
I know, I know, this sounds soo easy. But I can’t seem to find the correct answer on the Internet. One of the solution I found was to use is_dir. if(is_dir($dir)) echo ‘directory exists’; else …
What’s the point of using wordy Time Zones?
I know this isn’t specific to PHP, but what’s the point of using timezones listed like this :http://us2.php.net/manual/en/timezones.america.php? For example “America/Indianapolis” and “America/…
How to use nuSOAP for messages with multiple namespaces
I’m trying to access a WebService using nuSOAP (because I’m bound to PHP4 here) that uses more than 1 namespace in a message. Is that possible? An example request message would look like this: <…
Are singleline if statements or if statements without braces bad practice?
I was told that the first instance wasn’t a good idea. I have no idea whether this is really this case (or for the second one either); does it not shorten the amount to type? Or is it because it just makes a mess? Answer The best practice is to write code that others can read and update easily. Your
MySQL query to extract first word from a field
I would like to run a query that returns the first word only from a particular field, this field has multiple words separated by spaces, I assume I may need to carry out some regex work to accomplish this? I know how to do this using a few ways in PHP but this would best be carried out on the