Posts Tagged php
linux php installation
To compile PHP
- $ cd /usr/src
- $ tar -zxvf php-4.3.0.tar.gz
- $ cd /usr/src/php-4.3.0
- $ ./configure –prefix=/wwwroot/php –with-apxs2=/wwwroot/bin/apxs –with-config-file-path=/wwwroot/php –with-mysql
- $ make
- $ make install
Now you have to edit Apache configuration file /wwwroot/conf/httpd.conf.
If LoadModule php4_module modules/libphp4.so line hasn’t been added by php install to /wwwroot/conf/httpd.conf, then you have to add it yourself. Add it somewhere below section named “Dynamic Shared Object (DSO) Support”
LoadModule php4_module modules/libphp4. Now add this line to /wwwroot/conf/httpd.conf file:
Add Type application/x-httpd-php .php
Start Apache now:
$ /wwwroot/bin/apachectl start
Now create a test PHP file using any text editor and add these lines to it:
Save it under /wwwroot/htdocs as info.php
Now test PHP installation by accessing file info.php:
http://localhost/info.php
Add comment August 12, 2009
Write Your own Regular expression
In everyday work,we need to valid fields with regular expression. In hurry, we do google and got confused with so many options of same type validation. If we know the rules, than it will very easy to make our own expression.
We can make expression for different,but common cases :
- only character set: first name, last name, paragraph title.
- Name: ‘^[ \t\r\n]?[ \t\r\na-zA-Z._]+[ \t\r\n]?$’;
- Paragraph title: ‘^[ \t\r\n]?[ \ta-zA-Z]{10,80}[ \t\r\n]?$’;
- only number set: postcode, phone number, user id
- Phone number: ‘^[ \t\r\n]?[0-9]{8,16}[ \t\r\n]?$’
- Only Number: ‘^[ \t\r\n]?[0-9]{1,10}[ \t\r\n]?$’
- Post code: ‘^[ \t\r\n]?[0-9]{4,6}[ \t\r\n]?$’;
- only number and character set: Address,password
- Address: ‘^[ \t\r\n]?[ \t\n\/a-zA-Z0-9._%,-]*[ \t\r\n]?$’
- Password : ‘(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,12})$’ [with at least 1 character and 1 number]
- character with some special character :email address
- Email Address: ‘^([ \t\n\r\f\v]?)([a-z]{1})[a-z0-9._%-]+@[a-z0-9.-]+[.]([a-z]{2,4})([ \t\n\r\f\v]?)$’
Now, whan to do little discussion about this rules. I hope it will help to understand the meaning of signs. lets take the last expression,which one is created for Email. I have added color, to make some part of the expression.
RULES:^([ \t\n\r\f\v]?)([a-z]{1})[a-z0-9._%-]+@[a-z0-9.-]+[.]([a-z]{2,4})([ \t\n\r\f\v]?)$’
([ \t\n\r\f\v]?) ->with this ‘?’ it indicate that,there can be one or Zero \t (tab), \n (new line)
([a-z]{1}) ->with this ‘{1}’ indicate that,there must be 1 character any one of a to z.
[a-z0-9._%-] ->with this rules it defines that,there can be any one of [ a to z ] or [ 0 to 9] or [.(DOT)] or [-] or[ _ ].
+@ –>after those characters there must be a @ sign
[a-z0-9.-] ->with this rules it defines that,there can be any one of [ a to z ] or [ 0 to 9] or [.(DOT)] or [-] .
+[.] -> must be a DOT(.)
([a-z]{2,4}) -> should have character. and the length should be 2 to 4 character.
Example: hee9.llo_wor-ld@g8.com
Add comment July 14, 2009
Field validation with php
For creating a php file, at first we have to check all the fields input are valid. so, Field validation is our 1st step:
if(submit is ok){
if ( ! preg_match( “/^( [ tnrfv]* )+ ( [ a-zA-z_ ] ){ 4 , 20 }+/” , $fastname ) ){
$validation_flag=0;
$error_counter++;
}
else{
$validation_flag=1;
}
if ( ! preg_match( “/^( [ tnrfv]*)+( [ a-zA-Z0-9_- ]){ 4,20 }/”, $password ) ){
$validation_flag=0;
}else
$validation_flag=1;
if (!preg_match( “/^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)*.([a-zA-Z]{2,6})$/”, $email_address ) ) {
$validation_flag=0;
$error_counter++;
}else{
$validation_flag=1;
}
}
Add comment December 14, 2008