- PHP Secure Authentication of User Logins
61 comments - Most Used PHP Framework-The Popular Top 7 List in year 2011
46 comments - Blogger Robots.txt Tips
13 comments - Best Caching Plugin for Wordpress in 2011 is “Quick Cache”
11 comments -
Recent Posts
Sample Code Applications
- PHP Secure Login
- Video Streaming PHP Script Tutorial
- Statistical T-Test Online using PHP
- Custom Google XML Sitemap Generator
- Paypal IPN Shopping Page Demo using PHP
- Encrypt PHP code
- Compute Descriptive Statistics using PHP
- Calculate and Estimate Website Authority in Google
- Decimal Random Generator using PHP
- AJAX webform using Prototype library
- Sample AJAX Web Form
- PHP preg_match test online and Function Definition
Advertisement
PHP preg_match test online and Function Definition
Instructions:
Description and Definition: PHP preg_match is a function that is used when conducting regular expressions match in a string in a PHP programming environment.
The tool below will test any pregmatch condition using PHP.Testing pregmatch is often difficult without real script.There are so many uses of pregmatch function.
We can often see this to validate email address, domain names , etc.So if you are learning PHP programming language, this is one of the most useful functions.
This is very useful if you are formulating a condition to test a string using PHP pregmatch function. For example, say you are testing:
$pattern = "/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i";
echo preg_match ($pattern, "email-address-to-validate@host.tld");
(Example taken from PHP.net pregmatch page)
The condition is the one inside the double quote:
/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i
The above example is the use of pregmatch to validate email address. So if you enter the condition to test in the form below, in the next page, you will be
entering the string to test, which is an email address to test with the above condition.
One of the most important use of pregmatch is using it along with PHP conditionals such as an IF- THEN- ELSE statement. Supposing you have dynamic website that is powered with a template and then you need to show something to your user only when the URL is: www.php-developer.org/testpregmatch.php.
In your PHP template (header.php for example if you are using Wordpress CMS), you can execute the following conditionals as follows:
<?php
if (preg_match("/testpregmatch/i",$pageurl)) {
?>
<!--Show HTML code that you would like show only the URL that contains testpregmatch-->
<?php
}
else {
?>
<!--Otherwise show an alternate HTML code if the URL does not contain the string testpregmatch-->
<?php
}
?>
You can test any pregmatch condition below, and the corresponding string to be tested.
Download source code
Link To This Tool
1. Click inside the codebox2. Right-Click then Copy
3. Paste the HTML code into your webpage
codebox