Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New to PHP. Should I learn PCRE or POSIX. (saying both won't be helpful)

I was looking at a website that said use of POSIX is dying out in PHP 5.3.

I was also working though a video ISO (from around 2005) that said I should stick to POSIX if I'm new to PHP and have never programmed in Python.

I've read that PCRE is faster than POSIX. I don't what to go hardcore on a regex that's dying out. (I don't have any plans on learning Python for a long while)

POSIX looks quite easy to grasp as I've already been revising it but I don't care for what's easy I want to learn what works better for what I want to do. Which will be string manipulation, verification, & database stuff (once I get to that stage)

what should I learn? please give clear reasons for using either.

Thanks for your time

like image 819
Glacius Avatar asked Jan 21 '11 03:01

Glacius


People also ask

Does PHP use PCRE?

The PCRE extension is a core PHP extension, so it is always enabled. By default, this extension is compiled using the bundled PCRE library.

What is PCRE PHP?

The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5, with just a few differences (see below). The current implementation corresponds to Perl 5.005. +add a note.

Which has been considered the benchmark for powerful regular expression?

Perl has long been considered the benchmark for powerful regular expressions. PHP uses a C library called pcre to provide almost complete support for Perl's arsenal of regular expression features.


3 Answers

Learn PCRE (preg_* functions in PHP). POSIX regular expressions (ereg*, split functions in PHP) have been deprecated as of PHP 5.3, and should not be used anymore. This is the official recommendation. To quote the manual page:

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

like image 116
mfonda Avatar answered Oct 26 '22 09:10

mfonda


POSIX is obsolete and is deprecated.

like image 20
zerkms Avatar answered Oct 26 '22 09:10

zerkms


If by "POSIX" you mean the baseline, older style of regular expressions -- they are dinosaurs. Skip over them and learn Perl Compatible type regular expressions (which also applies to Python, Ruby, PHP, Java, Javascript, etc etc etc)

If by "POSIX" you mean the baseline compatible OS calls that are compatible over many Unixy operating systems -- these are very very important and not obsolete at all.

I think you mean the former. If so SKIP POSIX / BRE regular expressions -- learn Perl type regular expressions.

IF you mean the latter -- learning POSIX OS Concepts is important. (and I am still learning them...)

like image 38
the wolf Avatar answered Oct 26 '22 10:10

the wolf