The Regular Expressions cheat sheet is a one-page reference sheet. It is a guide to patterns in regular expressions, and is not specific to any single language.
regular-expressions-cheat-sheet
Blog contains various PHP, Javascript Code that would be helpful for website development. PHP is a open source scripting language useful to develop dynamic website.
Tuesday, 17 January 2012
Wednesday, 14 December 2011
How to Install Apache, PHP, MySQL and PHPMyAdmin in Ubuntu 11.04
If you are a PHP based web developer, you need all the software running and configured properly. Here I am talking about installing them One by One in your Ubuntu Desktop. We are installing all the applications from terminal.
How to Open Terminal:
So, to fire up the terminal follow any of these steps:
How to install Apache:
1. Make sure you have the internet connection. To install apache execute the following command in the terminal:
It takes some time to download and install apache. After the setup completes, type http://localhost/ in your browser window to make sure apache is installed and running properly. If you see the page with It Works!, the setup of apache2 completes successfully.
How to Install PHP:
1. To install PHP 5, type following commands in the terminal one by one:
The first line installs PHP5 in the computer. The second one provides the PHP5 module for the Apache 2 webserver. If second one is not installed, then Apache cannot parse PHP codes in a web page.
2. After installing PHP5 and PHP module for apache, restart the apache with following code:
3. While restarting the apache server, if you see a warning as “Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName”, then you can fix this by creating a file with the Server name. To do this type the following command in the terminal:
When the text editor opens, type “ServerName localhost” inside the file and click Save. Then close it. Now restart again with the above code and you will see that the warning message has gone.
4. Now, we have successfully installed php and apache web server. However, still we don’t know if PHP is successfully installed. To check this, create a file inside /var/www/ folder named test.php as:
and write following code in it
Save the file and type this in browser: http://localhost/test.php
If you see the various information about PHP and installed modules there, then we can confirm that Apache is parsing PHP codes. Hence the installation is successful up to this point.
How to Install MySQL:
1. To install MySQL Server in ubuntu, type following code in terminal window:
This will install latest mysql server and other necessary PHP modules for recognizing mysql functions from PHP code. While installing MySQL server, you may require to enter the password for MySQL root user.
How to Install PHPMyAdmin:
1. To Install PHPMyAdmin, type the following codes in the terminal:
While installing PHPMyAdmin, you may require to select the web server. In such case, tick the Apache2 Server and proceed with the installation. You may also require to input MySQL root user password during installation.
Once the installation completes, type this in your browser window to confirm the successful installation of PHPMyAdmin: http://localhost/phpmyadmin/index.php.
Now, you are finished. Your environment is setup and you can enjoy using all these applications. Next, you can install other applications that may be necessary such as Eclipse, GIMP etc.
How to Open Terminal:
So, to fire up the terminal follow any of these steps:
- If you are running Unity Desktop, click on the Ubuntu Logo at top left corner and type Terminal in the search application bar. Then click on the terminal icon.
- If you are running GNome Desktop, click on Applications->Accessories->Terminal
- For shortcut, you can also press Ctrl+Alt+T at once, to open the terminal.
How to install Apache:
1. Make sure you have the internet connection. To install apache execute the following command in the terminal:
1 | sudo apt-get install apache2 |
It takes some time to download and install apache. After the setup completes, type http://localhost/ in your browser window to make sure apache is installed and running properly. If you see the page with It Works!, the setup of apache2 completes successfully.
How to Install PHP:
1. To install PHP 5, type following commands in the terminal one by one:
1 2 | sudo apt-get install php5sudo apt-get install libapache2-mod-php5 |
The first line installs PHP5 in the computer. The second one provides the PHP5 module for the Apache 2 webserver. If second one is not installed, then Apache cannot parse PHP codes in a web page.
2. After installing PHP5 and PHP module for apache, restart the apache with following code:
1 | sudo /etc/init.d/apache2 restart |
3. While restarting the apache server, if you see a warning as “Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName”, then you can fix this by creating a file with the Server name. To do this type the following command in the terminal:
1 | sudo gedit /etc/apache2/conf.d/fqdn |
When the text editor opens, type “ServerName localhost” inside the file and click Save. Then close it. Now restart again with the above code and you will see that the warning message has gone.
4. Now, we have successfully installed php and apache web server. However, still we don’t know if PHP is successfully installed. To check this, create a file inside /var/www/ folder named test.php as:
1 | sudo gedit /var/www/test.php |
and write following code in it
1 | <?php phpinfo(); ?> |
Save the file and type this in browser: http://localhost/test.php
If you see the various information about PHP and installed modules there, then we can confirm that Apache is parsing PHP codes. Hence the installation is successful up to this point.
How to Install MySQL:
1. To install MySQL Server in ubuntu, type following code in terminal window:
1 | sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql |
This will install latest mysql server and other necessary PHP modules for recognizing mysql functions from PHP code. While installing MySQL server, you may require to enter the password for MySQL root user.
How to Install PHPMyAdmin:
1. To Install PHPMyAdmin, type the following codes in the terminal:
1 | sudo apt-get install phpmyadmin |
While installing PHPMyAdmin, you may require to select the web server. In such case, tick the Apache2 Server and proceed with the installation. You may also require to input MySQL root user password during installation.
Once the installation completes, type this in your browser window to confirm the successful installation of PHPMyAdmin: http://localhost/phpmyadmin/index.php.
Now, you are finished. Your environment is setup and you can enjoy using all these applications. Next, you can install other applications that may be necessary such as Eclipse, GIMP etc.
Tuesday, 29 November 2011
The Right Way to Get a File Extension in PHP
I made a recent search on retrieving file extensions in PHP.
I found out that a lot have been re-inventing the wheel. They have been creating code for functionality that PHP already has. This is one example of re-inventing the wheel
function get_file_extension($file_name)
{
return substr(strrchr($file_name,'.'),1);
}
Another example was this:
function file_extension($filename)
{
return end(explode(".", $filename));
}
PHP already has a function that does the same thing and more.
Welcome, pathinfo.
$file_path = pathinfo('/www/htdocs/your_image.jpg');
echo "$file_path ['dirname']\n";
echo "$file_path ['basename']\n";
echo "$file_path ['extension']\n";
echo "$file_path ['filename']\n"; // only in PHP 5.2+
// Output
/www/htdocs
your_image.jpg
jpg
your_image
A much easier way to use the constants:
[PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME]
PATHINFO_DIRNAME - the directory
PATHINFO_BASENAME - the file name
PATHINFO_EXTENSION - the extension
PATHINFO_FILENAME - the filename without the extension
echo pathinfo('/www/htdocs/your_image.jpg', PATHINFO_EXTENSION);
// Output
jpg
I found out that a lot have been re-inventing the wheel. They have been creating code for functionality that PHP already has. This is one example of re-inventing the wheel
function get_file_extension($file_name)
{
return substr(strrchr($file_name,'.'),1);
}
Another example was this:
function file_extension($filename)
{
return end(explode(".", $filename));
}
PHP already has a function that does the same thing and more.
Welcome, pathinfo.
$file_path = pathinfo('/www/htdocs/your_image.jpg');
echo "$file_path ['dirname']\n";
echo "$file_path ['basename']\n";
echo "$file_path ['extension']\n";
echo "$file_path ['filename']\n"; // only in PHP 5.2+
// Output
/www/htdocs
your_image.jpg
jpg
your_image
A much easier way to use the constants:
[PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME]
PATHINFO_DIRNAME - the directory
PATHINFO_BASENAME - the file name
PATHINFO_EXTENSION - the extension
PATHINFO_FILENAME - the filename without the extension
echo pathinfo('/www/htdocs/your_image.jpg', PATHINFO_EXTENSION);
// Output
jpg
Friday, 21 October 2011
Building your house
An elderly carpenter was ready to retire. He told his employer-contractor of his plans to leave the house-building business to live a more leisurely life with his wife and enjoy his extended family. He would miss the paycheck each week, but he wanted to retire. They could get by.
The contractor was sorry to see his good worker go & asked if he could build just one more house as a personal favor. The carpenter said yes, but over time it was easy to see that his heart was not in his work. He resorted to shoddy workmanship and used inferior materials. It was an unfortunate way to end a dedicated career.
When the carpenter finished his work, his employer came to inspect the house. Then he handed the front-door key to the carpenter and said, “This is your house…my gift to you.
“The carpenter was shocked!
What a shame! If he had only known he was building his own house, he would have done it all so differently.
So it is with us. We build our lives, a day at a time, often putting less than our best into the building. Then, with a shock, we realize we have to live in the house we have built. If we could do it over, we would do it much differently.
But, you cannot go back. You are the carpenter, and every day you hammer a nail, place a board, or erect a wall. Someone once said, “Life is a do-it-yourself project. “Your attitude, and the choices you make today, help build the “house” you will live in tomorrow. Therefore, build wisely!
The contractor was sorry to see his good worker go & asked if he could build just one more house as a personal favor. The carpenter said yes, but over time it was easy to see that his heart was not in his work. He resorted to shoddy workmanship and used inferior materials. It was an unfortunate way to end a dedicated career.
When the carpenter finished his work, his employer came to inspect the house. Then he handed the front-door key to the carpenter and said, “This is your house…my gift to you.
“The carpenter was shocked!
What a shame! If he had only known he was building his own house, he would have done it all so differently.
So it is with us. We build our lives, a day at a time, often putting less than our best into the building. Then, with a shock, we realize we have to live in the house we have built. If we could do it over, we would do it much differently.
But, you cannot go back. You are the carpenter, and every day you hammer a nail, place a board, or erect a wall. Someone once said, “Life is a do-it-yourself project. “Your attitude, and the choices you make today, help build the “house” you will live in tomorrow. Therefore, build wisely!
2 Monks and a Pretty Lady
Once upon a time a big monk and a little monk were traveling together. They came to the bank of a river and found the bridge was damaged. They had to wade across the river.
There was a pretty lady who was stuck at the damaged bridge and couldn’t cross the river.
The big monk offered to carry her across the river on his back to which the lady accepted.
The little monk was shocked by the move of the big monk and was thinking “How can big brother carry a lady when we are supposed to avoid all intimacy with females?” But he kept quiet.
The big monk carried the lady across the river and the small monk followed unhappily. When they crossed the river, the big monk let the lady down and they parted ways with her.
All along the way for several miles, the little monk was very unhappy with the act of the big monk. He was making up all kinds of accusations about big monk in his head. This got him madder and madder. But he still kept quiet. And the big monk had no inclination to explain his situation.
Finally, at a rest point many hours later, the little monk could not stand it any further, he burst out angrily at the big monk. “How can you claim yourself a devout monk, when you seize the first opportunity to touch a female, especially when she is very pretty?”
All your teachings to me make you a big hypocrite.
The big monk looked surprised and said, “I had put down the pretty lady at the river bank many hours ago, how come you are still carrying her along?”
Moral: This very old Chinese Zen story reflects the thinking of many people today. We encounter many unpleasant things in our life, they irritate us and they make us angry. But like the little monk, we are not willing to let them go away. There is no point in remaining hurt by the unpleasant event after it is over. Learn to move on in life!
There was a pretty lady who was stuck at the damaged bridge and couldn’t cross the river.
The big monk offered to carry her across the river on his back to which the lady accepted.
The little monk was shocked by the move of the big monk and was thinking “How can big brother carry a lady when we are supposed to avoid all intimacy with females?” But he kept quiet.
The big monk carried the lady across the river and the small monk followed unhappily. When they crossed the river, the big monk let the lady down and they parted ways with her.
All along the way for several miles, the little monk was very unhappy with the act of the big monk. He was making up all kinds of accusations about big monk in his head. This got him madder and madder. But he still kept quiet. And the big monk had no inclination to explain his situation.
Finally, at a rest point many hours later, the little monk could not stand it any further, he burst out angrily at the big monk. “How can you claim yourself a devout monk, when you seize the first opportunity to touch a female, especially when she is very pretty?”
All your teachings to me make you a big hypocrite.
The big monk looked surprised and said, “I had put down the pretty lady at the river bank many hours ago, how come you are still carrying her along?”
Moral: This very old Chinese Zen story reflects the thinking of many people today. We encounter many unpleasant things in our life, they irritate us and they make us angry. But like the little monk, we are not willing to let them go away. There is no point in remaining hurt by the unpleasant event after it is over. Learn to move on in life!
Subscribe to:
Posts (Atom)