Posts filed under '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
Using regular expression with PHP
Before use a regular expression, you have to create your own regular expression depending on your projectes requirments. lets think about password. What you do, if you have password restriction like: password must have letter and number. And there must be 1 letter and 1 number.
- Create my regular expression with rules:
- ‘(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,12})$’;
- Create object to use this rules:
- var regObjPass = new RegExp();
- Store this rules in a variable:
- var passRegExp = ‘(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,12})$’;
- Use this rules for compile:
- regObjPass.compile(passRegExp);
- Take the field’s value and store it in a variable:
var agentPass = frmName.agentPass.value - Now, apply the condition and check the field for validation
- if(agentPass==” ){
errorMsg=errorMsg+”\n# Password field can’t be blank”;
flag= false;
}
else if(!regObjPass.test(agentPass) ){
errorMsg=errorMsg+ “\n# Password must have 1 digit & 1 character.\n Password can’t contain any special character.\n Password length must be 6 to 12.” ;
flag= false;
}
- if(agentPass==” ){
Add comment July 14, 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