| Other Added |
Hubs | Hubbers | Topics | Request |
| #1 in Business | Subscribe Email Print |
|
You are here: Home > Internet and Businesses Online > Web Development > Introduction To Regular Expressions In PHP |
|
Other Added - Introduction To Regular Expressions In PHP
eCourses: Promoting Your Product? Offer a Free eCourse From Your Website [:space:] will match a whitespace character.What is an ecourse?Ecourse is a series of emails sent to the subscribers at a specified interval. This can be achieved by a follow up autoresponder software that can be loaded with email messages and it sends the messages at specified intervals.Tips in creating an ecourse:1. Make your ecourse short like 5 - 10 messages. Too many messages makes the subscriber lose his focus. If possible keep links to previous email messages.2. Divide the topic in to 5 - 10 subtopics. Example if you are sending a search engine optimization course, then you can divide your topic like:= Day 1: Search engine friendly urls = Day 2: Linking from and within your website = Day 3: Keywords and Metatags = Day 4: How and where to put content = And so on....3. Make Modifiers A modifier alters the meaning of the immediately preceding pattern character. - An asterisk ('*') matches 0 or more of the preceding term. Example 'a*' will match '', 'a', 'aa', 'aaaaa' and so on (Note the use of ''. It simply means that the expression matches nothing as well). - A question mark ('?') matches 0 or 1 of the preceding term. Example 'a?' will match '' and 'a' only. - A plus sign ('+') matches 1 or more of the preceding term. Example 'a+' will match 'a', 'aaaaaaa' and so on. It will not match ''. - {m,n} matches between m and n occurences of the preced Why Buying an Opt-In List Is the Worst Thing To Do For Your Business In Linux and Unix, the syntax that is commonly used by many applications for specifying text patterns is known as regular expressions or in short form - regex. Regex is a very powerful technique to describe patterns and many programs use them to describe sequences of characters to be matched. Search programs such as 'grep' rely heavily on regex. Basically regex forms the core in the linux world. Many scripting languages such as perl, ruby, php...etc has build in regex functions as well. So you can see, learning regular expression is important because they are used alot in many places and probably more so in the future.The title is a strong statement, I know. But it needs to be addressed.Some email marketers – the self-proclaimed “email marketers” – will tell you that the easiest and best way to build your list is to simply purchase one. Sure, it’s real easy to acquire a list for your email marketing by just buying one. They're not too expensive, and they provide you with a long list of names and email addresses. Ok, I’ll buy that…it may be the easiest, but it’s certainly not the best. In fact, it’s the worst way to build your list.It may be easy, and you may quickly gather a large list of email addresses – but all of those email addresses are nothing more but addresses. You don’t know the people on the receiving end of those addresses. Essentially, the people on the receiving end are uninterested peopl Regex can be scary at first but if you can get the basics, it is really not too hard to understand. In this article, we are going to look at how regex comes into the picture when writing php applications. To do a quick summary so far, a regular expression is a sequence of literal characters, wildcards, modifiers and anchors. Literal Characters Literal characters are letters, digits and special characters that match only themselves. Examples are abc, 123, ~@ and so on (some characters are reserved though). - An inclusion range [m-n] matches one of any character included in the range from m to n. Example '[a-z]' will match any alpha character that falls within the a to z range. - An exclusion range [^m-n] matches one of any character not included in the range from m to n. Example '[^0-9]' will match any non-digit character. - A period "." matches any character. It is also known as the wildcard. Example 'a.c' will match 'aec', 'acc', 'a@a' and so on. - The escape character '' enable interpretation of special characters. Example 'a.c' will match 'ac' only. Remember that '.' is a reserved character to represent a wildcard? Therefore to match a period, ie '.', we need to escape it like so '.' - The expression [:alnum:] will match all alpha-numeric characters. It is a shortcut to [A-Za-z0-9]. As you can see, it is not really a shortcut. The expression [:alnum:] might be easier to remember for some people. - The expression [:alpha:] will match all alpha characters. It is a shortcut to [A-Za-z]. - The expression [:blank:] will match a space or tab. - The expression [:digit:] will match a numeric digit. It is a shortcut to [0-9]. - The expression [:lower:] will match all lowercase letters. It is a shortcut to [a-z]. - The expression [:upper:] will match all uppercase letters. It is a shortcut to [A-Z]. - The expression [:punct:] will match all printable characters, excluding spaces and alphanumerics. - The expression [:space:] will match a whitespace character. Modifiers A modifier alters the meaning of the immediately preceding pattern character. - An asterisk ('*') matches 0 or more of the preceding term. Example 'a*' will match '', 'a', 'aa', 'aaaaa' and so on (Note the use of ''. It simply means that the expression matches nothing as well). - A question mark ('?') matches 0 or 1 of the preceding term. Example 'a?' will match '' and 'a' only. - A plus sign ('+') matches 1 or more of the preceding term. Example 'a+' will match 'a', 'aaaaaaa' and so on. It will not match ''. - {m,n} matches between m and n occurences of the precedi No Degree, No Problem ou can get the basics, it is really not too hard to understand. In this article, we are going to look at how regex comes into the picture when writing php applications.According to a recent survey, 52% of job candidates polled lied on their resume about having a college degree. Here are 3 brief horror stories: A new Director of Logistics and his family were actually loading the moving van provided by his new employer for relocation from California to North Carolina. The phone rang and it was the Human Resource Manager from his new company. The offer was being withdrawn. Through a routine degree verification check, the company learned the potential new employee did not have a degree. He was 3 hours short of graduating. Had the candidate been honest, the job was still his. It was an integrity issue. Five candidates for a high level software sales job were interviewing. After the face to face interviews, the can To do a quick summary so far, a regular expression is a sequence of literal characters, wildcards, modifiers and anchors. Literal Characters Literal characters are letters, digits and special characters that match only themselves. Examples are abc, 123, ~@ and so on (some characters are reserved though). - An inclusion range [m-n] matches one of any character included in the range from m to n. Example '[a-z]' will match any alpha character that falls within the a to z range. - An exclusion range [^m-n] matches one of any character not included in the range from m to n. Example '[^0-9]' will match any non-digit character. - A period "." matches any character. It is also known as the wildcard. Example 'a.c' will match 'aec', 'acc', 'a@a' and so on. - The escape character '' enable interpretation of special characters. Example 'a.c' will match 'ac' only. Remember that '.' is a reserved character to represent a wildcard? Therefore to match a period, ie '.', we need to escape it like so '.' - The expression [:alnum:] will match all alpha-numeric characters. It is a shortcut to [A-Za-z0-9]. As you can see, it is not really a shortcut. The expression [:alnum:] might be easier to remember for some people. - The expression [:alpha:] will match all alpha characters. It is a shortcut to [A-Za-z]. - The expression [:blank:] will match a space or tab. - The expression [:digit:] will match a numeric digit. It is a shortcut to [0-9]. - The expression [:lower:] will match all lowercase letters. It is a shortcut to [a-z]. - The expression [:upper:] will match all uppercase letters. It is a shortcut to [A-Z]. - The expression [:punct:] will match all printable characters, excluding spaces and alphanumerics. - The expression [:space:] will match a whitespace character. Modifiers A modifier alters the meaning of the immediately preceding pattern character. - An asterisk ('*') matches 0 or more of the preceding term. Example 'a*' will match '', 'a', 'aa', 'aaaaa' and so on (Note the use of ''. It simply means that the expression matches nothing as well). - A question mark ('?') matches 0 or 1 of the preceding term. Example 'a?' will match '' and 'a' only. - A plus sign ('+') matches 1 or more of the preceding term. Example 'a+' will match 'a', 'aaaaaaa' and so on. It will not match ''. - {m,n} matches between m and n occurences of the preced Increase Web Traffic – How to Generate More Web Traffic Fast he a to z range.So you have just gotten online, you have a web site and some kind of product or system you want to promote. You know that you need to increase your web traffic if you are going to succeed, and you know that the faster you increase your web site traffic, the faster your new web business will grow.So how do you increase web traffic fast?First of all, I must tell you this: most of the guaranteed traffic and ‘get a million hits’ types of programs are a waste of money in my opinion. I have tried several of them and have found that I wasted my money. You need a real web traffic increase, and you need it fast, so I recommend bypassing those crazy strategies, take this free strategy by faith, and increase your web traffic without spending ridiculous amounts of money on empty promises.Here is - An exclusion range [^m-n] matches one of any character not included in the range from m to n. Example '[^0-9]' will match any non-digit character. - A period "." matches any character. It is also known as the wildcard. Example 'a.c' will match 'aec', 'acc', 'a@a' and so on. - The escape character '' enable interpretation of special characters. Example 'a.c' will match 'ac' only. Remember that '.' is a reserved character to represent a wildcard? Therefore to match a period, ie '.', we need to escape it like so '.' - The expression [:alnum:] will match all alpha-numeric characters. It is a shortcut to [A-Za-z0-9]. As you can see, it is not really a shortcut. The expression [:alnum:] might be easier to remember for some people. - The expression [:alpha:] will match all alpha characters. It is a shortcut to [A-Za-z]. - The expression [:blank:] will match a space or tab. - The expression [:digit:] will match a numeric digit. It is a shortcut to [0-9]. - The expression [:lower:] will match all lowercase letters. It is a shortcut to [a-z]. - The expression [:upper:] will match all uppercase letters. It is a shortcut to [A-Z]. - The expression [:punct:] will match all printable characters, excluding spaces and alphanumerics. - The expression [:space:] will match a whitespace character. Modifiers A modifier alters the meaning of the immediately preceding pattern character. - An asterisk ('*') matches 0 or more of the preceding term. Example 'a*' will match '', 'a', 'aa', 'aaaaa' and so on (Note the use of ''. It simply means that the expression matches nothing as well). - A question mark ('?') matches 0 or 1 of the preceding term. Example 'a?' will match '' and 'a' only. - A plus sign ('+') matches 1 or more of the preceding term. Example 'a+' will match 'a', 'aaaaaaa' and so on. It will not match ''. - {m,n} matches between m and n occurences of the preced My Dumbest Marketing Blunder And How You Can Avoid It can see, it is not really a shortcut. The expression [:alnum:] might be easier to remember for some people.When I started submitting Ezine articles, I never realized their true power. I was just happy to see the articles being published.I expected to get some traffic and hopefully some sales. I would have laughed if you told me those early words would still be floating around the web over five years later.Well, smack me on the wrist and call me shorty, they are. You would think that's a good thing and it is except... That's the operative word, "except." The little critters are still multiplying around the web like rabbits in heat, but there is a little problem. Actually, the problem isn't so little.This darn problem haunts me. At least a couple of times a week it drives me insane. Whenever I run across it I feel like the dullest axe in the shed.If I were double jointed, I'd kick myself - The expression [:alpha:] will match all alpha characters. It is a shortcut to [A-Za-z]. - The expression [:blank:] will match a space or tab. - The expression [:digit:] will match a numeric digit. It is a shortcut to [0-9]. - The expression [:lower:] will match all lowercase letters. It is a shortcut to [a-z]. - The expression [:upper:] will match all uppercase letters. It is a shortcut to [A-Z]. - The expression [:punct:] will match all printable characters, excluding spaces and alphanumerics. - The expression [:space:] will match a whitespace character. Modifiers A modifier alters the meaning of the immediately preceding pattern character. - An asterisk ('*') matches 0 or more of the preceding term. Example 'a*' will match '', 'a', 'aa', 'aaaaa' and so on (Note the use of ''. It simply means that the expression matches nothing as well). - A question mark ('?') matches 0 or 1 of the preceding term. Example 'a?' will match '' and 'a' only. - A plus sign ('+') matches 1 or more of the preceding term. Example 'a+' will match 'a', 'aaaaaaa' and so on. It will not match ''. - {m,n} matches between m and n occurences of the preced Managing After Downsizing [:space:] will match a whitespace character.So, you survived the downsizing. Your company did something that will probably show minimal, if any, return -- and will make your job as a manager a living hell. Your life has changed dramatically. People on your staff are frightened, fearful that they may be next to go. They will lie low hoping that they can be spared the next swing of the ax. (You may be feeling the same thing as well.) Teamwork will decrease as people begin to view the person next to them as a threat to that increasingly scarce resource -- a job.At the same time, you will be encouraged to build a strong work unit capable of handling the challenges -- you know the drill. Your financial targets will get higher. You will find that everyone is expected to do more with less. Hours and stress will undoubtedly increase. Welcome to the new Modifiers A modifier alters the meaning of the immediately preceding pattern character. - An asterisk ('*') matches 0 or more of the preceding term. Example 'a*' will match '', 'a', 'aa', 'aaaaa' and so on (Note the use of ''. It simply means that the expression matches nothing as well). - A question mark ('?') matches 0 or 1 of the preceding term. Example 'a?' will match '' and 'a' only. - A plus sign ('+') matches 1 or more of the preceding term. Example 'a+' will match 'a', 'aaaaaaa' and so on. It will not match ''. - {m,n} matches between m and n occurences of the preceding term. Example 'a{1,3}' will match 'a', 'aa' and 'aaa' only. - {n} matches exactly n occurences of the preceding term. Example 'a{2}' will match 'aa' only. Anchors Anchors establish the context for the pattern such as "the beginning of a word" or "end of word". - The pike '^' marks the beginning of a line. Example '^http' will match any new line that starts with 'http'. - The dollar sign '$' marks the end of a line. Example 'after$' will match any line that ends with 'after'. (Variables in php starts with $. Try not to confuse with it). Grouping Grouping '( )' allows modifiers to apply to groups of regex specifiers instead of only the immediately proceding specifier. Example '( aa | bb )' will match either 'aa' or 'bb' Enough of boring stuff, it is time to put what the theory of regex into good use. PHP Implementation There are 2 main variants of regex, Perl-compatible regex (PCRE) and POSIX-Extended. PHP offers quite alot of functions to implement these 2 types of regex. In PHP, the most commonly used PCRE function is 'preg_match' and in POSIX-extended regex, 'ereg'. Both syntax are slightly different but equally powerful. The preference to use 'preg_match' or 'ereg' is entirely up to individual although Zend suggested that preg_match is slightly faster. I prefer to use 'eregi' simply because of my background in linux administration. Example 1: Matching United States 5 or 9 digit zip codes Zip codes in USA have the following format ##### or #####-#### where # is a digit. If you want to verify the zip code submitted say from an online form, you will need to use regex somewhere in your script to verify it. The matching POSIX-extended regex pattern will be: [[:digit:]]{5}(-[[:digit:]]{4})? Confused? Wait, let me explain why. This regex is split up into 2 parts: [[:digit:]]{5} and (-[[:digit:]]{4})?. First Part: '[[:digit:]]' means the digit range and {5} means that the digit must occur 5 times. Second Part: The bracket '( )' groups the '-[[:digit:]]{4}' together and the '?' means the expression '(-[[:digit:]]{4})' can either occur 0 or 1 time. To implement the regex in PHP, we use the following code: $zipCodes = 'xxxxx-xxxx'; $pattern = '[[:digit:]]{5}(-[[:digit:]]{4})?'; if (ereg($pattern,$zipCodes)) { echo "matched found "; } else { echo "match not found"; } Example 2: Matching Dates Say we want to verify the dates entered by the user. If we only accept dates like "YYYY-MM-DD" or "YYYY-M-D", the regex pattern will be [0-9]{4}(
HTTP = HTML link (for blogs, profiles,phorums):
Related Articles:5 Hot Tips for the Home Based Business Entrepreneur Career Breaks for Older Workers Make Money Online: Three Fast Ways to Make Money Online
|