If you have used my WordPress readme generator you would have noticed that I have a “Save As” button, which when pressed allows you to download the file which was just generated by the PHP code. (In most browsers this opens the save file as dialog box)
Recently one of the readers of my blog asked me how to do this in PHP and I was about to send him the code snippet. But then I thought of writing a blog article so that it will be useful for others as well.
So here we go.
The code is mostly self explanatory. The important part in the above code snippet is the “content Disposition” header.
Also since we are sending headers to the browser, we should not have started the output before this code executes. Otherwise we might get a “header already sent” error.
Recently, I wanted to play around with some stuff which is available only in PHP 5.3.x (more about it later in a separate blog post) and so was looking for a way to install it on my Ubuntu server, where this blog is running.
After poking around a bit, I found that Karmic Ubuntu hasn’t upgraded to PHP 5.3.x yet and the only way to do is to compile from PHP source. Even though I am pretty comfortable doing it, I didn’t wanted to do it, because it is very difficult to upgrade at a later point in time.
I was continuing my research and then found that it is in fact possible to install PHP 5.3.x though apt-get or aptitude. I thought of documenting it here, so that it would be useful for others who want to do the same thing.
Adding dotdeb to the source list
First you should add dotdeb repository to your apt-get source list. Add the following two lines to your /etc/apt-get/sources.list file
sudo vim /etc./apt-get/sources.list
Adding dotdeb keys to keyring
Dotdeb packages are GPGsigned. Issue the following commands to add the keys to key-ring
Install PHP5 packages
Then issue the following command to retrieve the updated package list. I am using aptitude here; you can use apt-get as well.
sudo aptitude update
sudo aptitude upgrade
And then you can install PHP5 packages (and modules) using the normal install command.
sudo aptitude install php5 libapache2-mod-php5
Installing php5-dev package
The above method will install all php5-* packages, but php5-dev has some dependency issues with libtool packages. In order to solve that you have to manually install libtool v1.5.26. To do that use the following commands.
Now it’s time to enjoy the new features that are available in PHP5.3 🙂
Just wrote quick some code sample to show how to access YQL (Yahoo Query Language) queries from PHP.
You can use the following code sample to fetch results from YQL from any standard PHP file. You would require the curl extension to be installed. If you are behind a proxy, uncomment the 3 lines and replace it with proper proxy values
If you have the Yahoo social SDK installed and you want to access results from YQL, then you can use the following code sample. Replace the text consumer_key and consumer_secret with correct values.