Please wait while loading...

Read more Verify email address by PHP filter_var

To check an email address is valid or not, we always use preg_match. Today I found that php5 has already allow a function to do so, which is filter_var

filter_var($email, FILTER_VALIDATE_EMAIL)

However, most checking script include filter_var doesn't well checking the domain part. For example, an email xxx@xxx.com1 can pass the validation but .com1 is a invalid domain name, so I add some code to the function to imporve the function as below.

function verifyEmail($email) {
	if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
		return preg_match('/^([a-z]{2,4})$/', end(explode('.',$email)));
	return false;

Note: I have set 2-4 letter in the last part of the domain, but you may know there exists some special domain will not pass the validation (such as .travel, .museum)

filter_var also allow some more checking function, such as FILTER_VALIDATE_URL, FILTER_VALIDATE_IP, you may read detail on php.net

Read more JS added new input does not post

On developing a submition form, we will sometimes need a variable number of input for some options. In the case we usaully use jquery/js to dynamically add input fields to the form. However, today I face on a problem that the jquery added input does not post to the server side. Finally, I find the reason is related to the strcture of the html.

the html of my code

<table id="table">
			<td><input type="text" name="dynamic[]"></td>
			<td><input type="button" id="addmore"></td>


$(document).ready(function() {
	$("#addmore").click(function() { $("tbody",$("#table")).append(''); });

The reason cost the problem is the order of form and table. In the case, I have put the form inside the table which will make the added input not catch by the form, simply change to the following and the problem solve:


Read more Support docx, xlsx download for IE

header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Disposition: attachment; filename="'.$filename.'"');

Read more Convert array of any depth to xml

Example php 5.2 code to convert array of any depth to xml document:


Read more Welcome to my blog

I'am wonder my blog finally finished and ready to launch. As my bad design knowledge, the layout modified many times and finally I confirmed to use current design, hope that not bad to your mind!

I have not write blog long times since my Xanga was discarded. I'd like to share my mind and some working experience as I become a programmer now.

1 2