Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

explode or split with mutiple possible delimiters 1

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
I found sample #2 here

which claims to do exactly what I need but it is giving me a warning or error.

Code:
Warning: split() [function.split]: REG_ERANGE in /usr/haf/web/default.php on line 13

Warning: split() [function.split]: REG_ERANGE in /usr/haf/web/default.php on line 14

The syntax is as follows
Code:
list($mA,$dA,$yA)=split('[/-.]', $valA);
list($mB,$dB,$yB)=split('[/-.]', $valB);
if ($valA != '') $valA = $yA.'/'.$mA.'/'.$dA;
if ($valB != '') $valB = $yB.'/'.$mB.'/'.$dB;

If I add @ to prefix the split() function, no warning comes up on screen but the call fails, variables are empty.

All that said, am I doing something wrong or is the sample listed on php.net misleading ???

Thank you all in advance for your assistance!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
are you sure that the regex should not be

Code:
'[/.-]'

you seem to be reversed a bit. thus will be mis-using the dot character.
 
I really did not know it had to be in an exact order ... I thought about it as I looked at the example I cited and the code I typed, but then said to myself that that would not make any sense ... :)

From writing Unix scripts, I remember using [a-z,0-9] and the like to encompass a range of characters, it never occurred to me that in this case the order in which I specify them would make a difference.

I tried the code using the order as you pointed out and it works pretty well!

Oh well, live a little, learn a little ...

Thanks!



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
you're right. there is no need to have any particular order inside a character class. inside a character class the dot means just a dot. i did not properly read your post, i'm afraid!

the reason why your code did not work is because you put the dash between two characters. pcre then considered that you were asking for pattern matching between two characters (ie. from slash TO dot). which it couldn't deal with... by putting the dash at the end, pcre knows that you mean a dash.
 
And there is light at the end of the tunnel ... I love clarity, it makes me feel at ease with myself :)

Your explanation lifted a cloud off me - Thank you so very much for your assistance!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top