Pass a Value to Multiple PHP Variables
I had been taking UMUC 411 this week, an one-week online test drive class for University Maryland University College. I was too active in the class that I didn’t have anything to write about on the blog. Now the class was over, I’m back to schedule to finish my website redesign project.
I decided that today I’ll be focused on “Follow me†section:
This section was made up by four images. The first one is RSS feed and the last three are social networks. I noticed that the title, alt, and part of the image location for social networks have the same content. Therefore I came up with the following PHP line to pass the value in the title variable into both alt and image location variables:
$image = $alt = $title;
In the above statement, because of the pass variables rule for PHP, I placed title variable to the farthest right of the equal signs and placed variables need to be distributed before the title variable which contains the original value. For instance, I assigned “Twitter†string to $title. $image and $alt would also assign “Twitter†string.
Four PHP Command-Line Functions
Typically I never read the technical articles on ibm.com. They are long and complicated. However, I was very interested on an IBM article today when I googled “php linux command”. It is titled Use Command-line tools in PHP. I experienced shell_exec(), exec(), passthru(), and system() functions by following the article. It explains the different usages between these four functions. To summarize them:
- shell_exec() is similar to backtick(`) operator which I used most often.
- exec() assigns its output result to an array variable. Apart from that, it is the same as shell_exec().
- passthru() directly outputs the result without using the echo statement, but you can assign the last argument to it to output the error code for debugging purpose.
- system() acts like a hybrid between passthru() and exec().
One function I was having trouble is the system() function. The output of the function is similar to the passthru() function. However, I later aware that if a variable assigned to the system() function, the function outputs an array so that I can process them line by line.
Use Rhythmbox to sync with iPod Touch
Today I happened to be downloaded a music album online and an audio book from Librivox. I want to transfer them to my iPod Touch. The first program that I remembered to have iPod Touch/iPhone sync ability is Rhythmbox so I launched the program. After playing around its interface, I was beginning to love to use Rhythmbox.
Once I started Rhythmbox from the Sound & Video menu, I had to left-click the music player icon on the status bar and select Show Rhythmbox. The name of my iPod Touch was already listed under Devices, I just needed to add the music and audio book files that I downloaded. It automatically added the files when I dragged and dropped the downloaded files into the Music Player window. Rhythmbox doesn’t seem to support transfer the files directly to the playlist created under iPod Touch. I had to first copy the music files to the root of my iPod Touch and then drag them to the playlist.
The music album I downloaded works great on my iPod Touch, but it doesn’t recognize the audio book files as audio book even I converted them from mp3 to m4b using XCFA. Since Librivox provides separate chapter files for each audio book, I don’t care about using audio book feature in iPod Touch very much.
Two Ubuntu Tips on Using WebTycho (UMUC)
I will attend UMUC (University of Maryland University College) this coming Fall and decided to take a free online course called UMUC 411 to prepare my laptop for the upcoming class. This online class officially starts on next Monday, but I finished lectures and completed the first assignment today. While I was using the WebTycho (the UMUC online classroom management system), I had some problems with my Ubuntu laptop.
WebTycho does not seem to support Chromium so I switched back to Firefox. After I logged in, it states that it uses Real format as the default playback format for the audios and videos. I don’t want to install Linux version of the Real Player since it’s not open. I thought that there must be a Firefox plugin to play the Real file format in the Synaptic Package Manager. After some search in the manager, I found a package called gecko-mediaplayer and installed it. Based on its description, it is a browser plugin that uses MPlayer and NS4 API to stream the media inside the browsers. I reopened Firefox and noticed that there is a video after I logged in. I think that the video did not appear before is because there was no Real plugin installed. The Real media plays very well inside MPlayer.
In addition to Real, WebTycho also uses Java for some of its applications. The problem with Java is that the Java process always runs in the background until Firefox was closed. This means that once I logged in WebTycho, Java process started even I didn’t use a Java application. For some reason, Java installed on Ubuntu uses greater CPU power than Firefox. It makes very loud noise from my laptop’s fans. I don’t like noise like this, so I searched across the web to find a way to disable Java in Firefox 3. Unfortunately, the methods I found either applies to Firefox 1.5/2 or Windows version of Firefox 3. I then played around with System Monitor to see if I can get something from it. I happened to be found a solution to the problem by right-clicking the Java process in the System Monitor and chose Open Files. It lists all the files that are currently opened by Java program. I noticed that IcedTea are mentioned in the list and I thought this probably correspondence to one of the Firefox plugins. After I reopened Firefox once more and disabled this plugin, Java is no longer activate automatically. Fortunately, Firefox plugins can be enabled/disabled on the fly without restart the browser, I can enable it whenever I use a Java-based app.
Create PDF without using PHP PDFlib
I never used PDFlib on my website because the extension isn’t available in the PEAR Modules of my web host. PDFlib is a PHP extension for generating PDF documents dynamically. PHP extensions need to be installed separately apart from PHP. In my one year experience with PHP, I only used GD extension to generate images for use with CAPCHA and other random images. Therefore I don’t have enough experience to talk about these extensions.
Recently when I was searching for some useful PHP tutorials, I stumble across a PHP class that can generate PDF documents without PDFlib extension. I thought this is very useful since my web host doesn’t provide the extension. It’s called FPDF. After some experiments by following its tutorials, I felt it’s not too difficult to use once you know the Object Oriented Programming way of PHP. The class also has dozens of extended classes. They can be copied and used as the extensions of FPDF. One thing that I don’t like about is its website. When I went to the site, the first thing I noticed was that it uses iframe. I don’t like iframe since it isn’t bookmarkable. I wonder why it doesn’t use PHP include instead of iframe since this is a PHP-based website. Fortunately, I can open the frame in a new tab by right-clicking appropriate frame in Firefox so I can add the Scripts page to Update Scanner to check new scripts update.
More Than One Month Usage of Chromium
I used Google Chrome on Ubuntu 9.10 and switched to Chromium on Ubuntu 10.04. Apart from being open source, I can’t tell any difference between Google Chrome and Chromium. During the switch process from Firefox to Chromium in the web development environment, I didn’t have any problems since I mostly used server-side script languages. Recently I have been interested in MooTools JavaScript Framework and followed its guide to test the code in Chromium. All went well until I test the class code. It seems that Chromium does not support document.write() JavaScript function very well. It worked in Firefox after my test with Chromium failed. I’m not familiar with Chromium’s JavaScript engine, but in my experience, Chrome has similar problem since the early build of Chrome 1. Long time ago, I used Chrome 1 alpha as my default web development environment in Windows. It disappointed me that Chrome didn’t have a complete JavaScript engine yet. It is ashamed that Google still has little bit of problems with its browser’s JavaScript engine as the market share of Chrome continues to go up. As a user, my overall usage experience of Chromium is good. However, Chromium doesn’t suited for my web development yet.
