Replace ereg with preg_match

How to update to using preg_match on newer versions of PHP

I was recently developing on a newer version of PHP than what is currently used on most of our servers and I was getting a warning telling me that the function ereg was depreciated.

A little googling told me that is is going to be totally removed from PHP 6 so in the interest of keeping my code nice and up to date I made the following changes....

Use preg_match instead of ereg and wrap the expression with //

Simple!

Here is an example;

ereg("^[-]?[0-9]+([\.][0-9]+)?$", $var);

Becomes

preg_match("/^[-]?[0-9]+([\.][0-9]+)?$/", $var);


Recent posts View all

Ruby

Forcing a Rails database column to be not null

How you can force a table column to always have something in it with Rails

Writing Marketing

We've deleted an article's worth of unhelpful words

We've improved several pages across our site by removing words that add no value, and often detract from the article.