Posted: 2011-09-19
Category: Code snippets
It's been a while since it started coding again in PHP specially in PHP 5.3.0 and I've come across some interesting finding, for example some functions such as ereg, eregi and split are deprecated now in favor of a new library call Perl-Compatible Regular Expressions. For old coders (like me) we need to start updating our code to keep with the up to date standards.
A function I use a lot (for good or for bad) is split but as a matter of fact is one of the new deprecated functions on php so instead of calling it as usual (delimiter, string) now we have to call it using a perl-compatible regular expression (regex,string) as follows:
$email = "something@domain.com";
$parts = preg_split('/@/',$email);
Result:
Array ( [0] => something [1] => domain.com )
You can see it's the same result as the old split() function.
Hope this saves you some time.
Tweet


Comments
Oso96_2000
2011-10-31
Mmh, para algo asi, no es mas sencillo usar explode()?