News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Nikita Popov's Blog:
The true power of regular expressions
June 15, 2012 @ 08:42:57

Nikita Popov has a new (language agnostic) post to his blog today about one of the most powerful things you can use in your development - something that a lot of developers don't understand the true power of - regular expressions.

As someone who frequents the PHP tag on StackOverflow I pretty often see questions about how to parse some particular aspect of HTML using regular expressions. A common reply to such a question is: "You cannot parse HTML with regular expressions, because HTML isn't regular. Use an XML parser instead." This statement - in the context of the question - is somewhere between very misleading and outright wrong. What I'll try to demonstrate in this article is how powerful modern regular expressions really are.

He starts with the basics, defining the "regular" part of "regular expression" (hint: it has to do with predictability) and the grammar of the expressions. He talks about the Chomsky hierarchy and how it relates to the "regular" as well as a more complex mapping of expression to language rules. He talks about matching context-free and context-sensitive languages and unrestricted grammars as well.

0 comments voice your opinion now!
power regular expression define theory context


PHPMaster.com:
Practicing Regular Expressions with Search and Replace
November 23, 2011 @ 14:27:59

On PHPMaster.com today there's a new tutorial that shares a few regular expression tips about doing some search and replace in your content.

So how can you practice using regex if you are limited to just using them in your code? The answer is to use a utility, of which there are many, that uses regex for performing search and replace. I'm sure everyone is familiar with the standard "find x and replace it with y" type of search and replace. Most IDEs and text editors have built in regex engines to handle search and replace. In this article I'd like to walk through a series of exercises to help you practice using regex.

His examples are based on Netbeans but can be used in just about any IDE that supports regex (or even just your code). He shows how to match word boundaries, do some grouping, work with back references and doing some search/replace based on multiple groupings.

0 comments voice your opinion now!
regular expression practice search replace boundaries group backreference


PHPMaster.com:
Regular Expressions
September 27, 2011 @ 09:42:28

Regular expressions have always been something that have mystified developers, even those seasoned ones looking to match the most complicated data. If you're just venturing into the world of regex, PHPMaster.com has a good guide to help you wade through some of the basics.

It makes all the sense of ancient Egyptian hieroglyphics to you, although those little pictures at least look like they have meaning. But this… this looks like gibberish. What does it mean? [...] When you're looking to go beyond straight text matches, like finding "stud" in "Mustard" (which would fail btw), and you need a way to "explain" what you're looking for because each instance may be different, you've come to need Regular Expressions, affectionately called regex.

The include a (somewhat) complicated example regex string and break it down chunk by chunk - groupings, character sets, multiple matching, delimiters and more (the pattern matches valid email addresses). They show how to use it in PHP with preg_match, preg_replace and preg_match_all for different situations.

0 comments voice your opinion now!
regular expression introduction email match tutorial


Gareth Heyes' Blog:
PHP CSSReg
August 23, 2011 @ 10:21:40

Gareth Heyes has a recent post pointing out the port of a project of his, CSSReg (a filtering tool for user-provided stylesheets) over to PHP.

Just a quick post to mention the excellent work by Norman Hippert aka @thewildcat, he successfully converted my Javascript based CSSReg into PHP. I was meaning to do this but never found the time so it's pretty awesome that not only did thewildcat convert the code but found some nice bugs in my code and fixed them. Great work Norman thanks very much!

You can see a demo of it here and grab the source as a download here. You can find out more about the origins of CSSReg (and some of its siblings) in this other post from Gareth.

0 comments voice your opinion now!
cssreg regular expression javascript port demo


Leonid Mamchenkov's Blog:
PHP regular expression to match English/Latin characters only
August 18, 2011 @ 12:11:44

Leonid Mamchenkov has a quick new post to his blog sharing a regular expression that can be used to check that a string contains only English or Latin characters (no Unicode allowed).

Today at work I came across a task which turned out to be much easier and simpler than I originally thought it would. We have have a site with some user registration forms. The site is translated into a number of languages, but due to the regulatory procedures, we have to force users to input their registration details in English only. Using Latin characters, numbers, and punctuation.

Thankfully the PCRE regular expression engine bundled with PHP makes it simple - it uses a standard regular expression without anything special to accommodate for Unicode characters. He notes that adding the "/u" modifier to the expression makes it "totally malfunction" (where strings are treated as UTF-8). If you'd like an example of some of the tricks that go into supporting Unicode in a regex, see this comment in the PHP manual.

0 comments voice your opinion now!
regular expression example english latin unicode


Zoomzum Blog:
10 Powerful PHP Regular Expression For Developers
July 27, 2011 @ 09:02:10

On the Zoomzum blog there's a new post with ten regular expressions PHP developers can use to accomplish some common tasks (like email validation and date formatting checks).

Regular expression for the PHP developers, on of the most popular tool for validating data is the regular expression. In this list we provides some validation - string match, password match validation, email address validation, date format and many more which helps developer to make their application more fast and easy to execute. [...] Have you note that, regular expressions are more slower than the basic string function, its takes a short time to execute than any others.

Included in their list are things like:

  • Password Match Validation
  • Validate URL
  • Validate URL using Preg_match
  • UK Postcode Validation
  • SSN,ISBN and Zipcode Validation

A few of these could be done with either one or two string calls or some of the filtering functions that are included in PHP.

5 comments voice your opinion now!
regular expression hint list validate regexp


NETTUTS.com:
Caching, YQL, and Regular Expressions
November 10, 2010 @ 10:07:14

On NETTUTS.com today there's a new tutorial showing you how to work with YQL for pulling information from remote feeds and PHP (with regular expressions) to handle filtering and caching.

In today's tutorial, we're going to mix a handful of technologies. First, we'll review how to implement a simple form of text file caching with PHP. To illustrate this technique, we'll use the wonderful YQL to query Twitter's search API for a list of tweets which contain the string, "nettuts." Finally, we'll experiment with PHP's regular expression capabilities, and will turn all Twitter usernames and urls into clickable links.

They show you (with the help of a few screenshots) how to get the YQL system to work with your PHP scripts and how you can fun a simple query against it. They use a simple file-based caching technique and a regular expression (not the simplest thing, mind you) to extract usernames and links from the results.

0 comments voice your opinion now!
yql caching regular expression tutorial twitter


Noupe.com:
Getting Started with PHP Regular Expressions
August 24, 2009 @ 07:59:10

Noupe.com has posted a new guide to getting started with regular expressions in PHP. Regular expressions can be one of the most powerful tools at your disposal when used correctly.

The main purpose of regular expressions, also called regex or regexp, is to efficiently search for patterns in a given text. These search patterns are written using a special format which a regular expression parser understands.

They cover some of the basics - special characters and some examples using them (like $, d, and *) - before getting into the preg_* functions in PHP. They also include some handy examples to validate things like US zip codes, email format validation and removing duplicated words in a section of text.

0 comments voice your opinion now!
regular expression tutorial preg


CatsWhoCode.com:
15 PHP regular expressions for web developers
July 28, 2009 @ 10:09:49

On CatsWhoCode.com today there's a new article listing fifteen handy regular expressions you might find useful in your day-to-day development (as well as a brief introduction to what regular expressions are).

Regular expressions are a very useful tool for developers. They allow to find, identify or replace text, words or any kind of characters. In this article, I have compiled 15+ extremely useful regular expressions that any web developer should have in his toolkit.

Here's just some of the expressions on the list:

  • Enlight a word from a text
  • Remove repeated words (case insensitive)
  • Matching a XML/HTML tag
  • Matching hexadecimal color values
  • Parsing Apache logs
0 comments voice your opinion now!
regular expression tip example


PHPBuilder.com:
How Regular Are Your Expressions (The ABC's of PHP, Part 9)
May 20, 2009 @ 11:51:13

On PHPBuilder.com there's a new installment in their "ABCs of PHP" series posted - a look at working with regular expressions.

We've looked at strings, and numbers and all sorts of types of data, but we've not yet seen how to do something really important, and that's to look for and pull interesting parts out of the data we have, to do that where going to use some magic from the Perl world called "Regular Expressions".

They start simple by looking at what regular expressions are and how they work to match portions (or all) of a string. Thankfully, they chose to go with the preg_* functions (like preg_match and friends) for their matching over the ereg_* functions. They talk about direct matches, wildcards and partial matching.

0 comments voice your opinion now!
beginner tutorial expression regular



Community Events





Don't see your event here?
Let us know!


release list symfony framework zendserver laravel deployment package update introduction api tips podcast library opinion language series install interview community

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework