Checking Mime-Type of External URL Using PHP

I was overwhelmed by Mime-Type while I was working for a project. The problem is I don’t know how to retrieve the mime-type from a file, particularly file from another host. This url is the one I want t check its mime-type. Why do I have to check it? Because it doesn’t have proper extension for an image. Look how it shows ‘?v=1423061058’ as its extension. What is it!!!??

Continue reading Checking Mime-Type of External URL Using PHP

Returning Filename Only in PHP

How to strip file extension in PHP? I want to lose my filepath in my PHP string and then leave the filename without extension for the rest of it. I want to eliminate the darn extension! It’s very easy my friend. It’s basic, but it took me an hour to find the best solution. The solution is simple.
Continue reading Returning Filename Only in PHP

PHP Example: preg_match() USA Telephone Number Matching

I’ve practiced about how to match USA telephone number format in different format using preg_match() function. The first time I found the exercise is in the Learning PHP 5 by David Sklar. In B8 exercise we have to write PHP script: regular expression that flexibly matches a U.S. phone number whether or not it has parentheses around the area code and has its parts separated by spaces, hyphens, or periods.

Of course, there is the answer for this exercise. But, when I tried, It didn’t smoothly solve the problem. The script wasn’t able to filter double parentheses like “((“, “))”, “(( )”, or “( ))”. So, I have a will to fix it and here the fixed script.

Continue reading PHP Example: preg_match() USA Telephone Number Matching

How to Put Date from MySQL to Select HTML Tag with PHP

You may want to create editable data using PHP and HTML. You want to take your date type value to your <select> HTML tag. It is not difficult, but yes we need to be patient to code it.

First, you should call a query to your MySQL such as:

<?php
$sqlquery=mysql_query("select * from income where transaction_id='".$_GET['transaction']."'") or die(mysql_error());
$row = mysql_fetch_array($sqlquery);
?>

Second, you have to set the type of your date in your table to DATE type. Don’t set it to VARCHAR or INTEGER. Let your MySQL database rules what it’s programmed to be. You just need to explode, separate, and put it into different <select> tag, as follow:

Continue reading How to Put Date from MySQL to Select HTML Tag with PHP

How to Store Date from Select HTML Tag to MySQL

Storing a date from <select> HTML tag to MySQL database is not that easy. I spent three hours to find out how. First time I tried to, I was thinking that my script was not effective. But, after reading some tutorial I found my own way to do it. Here it is.

MySQL script

Put this script at the top of your PHP file because it needs to store data first and then execute the script after.

<?php
if(isset($_POST['submit'])):
  $thedate=$_POST['dateyear']."-".$_POST['datemonth']."-".$_POST['dateday'];
  mysql_query("insert into income values('','".$thedate."')");
endif;
?>

Continue reading How to Store Date from Select HTML Tag to MySQL

How to Install Apache and PHP 5 on Ubuntu

I found this site when I search the way to install Apache as webserver and PHP5 on my Ubuntu 10.10.

sudo apt-get install apache2

sudo apt-get install php5

sudo apt-get install libapache2-mod-php5

sudo /etc/init.d/apache2 restart

One said that you don’t need to run sudo apt-get install libapache2-mod-php5 command because it is done with sudo apt-getinstall apache2.