Hello:
Using PHP 4.3.11
The line: $strDate = preg_split('/[\.\/-]/', $my_date);
works to break apart a date in the form mm/dd/yyyy or mm.dd.yyyy or
mm-dd-yyyy
but the line: $strDate = preg_split('/[\/-\.]/', $my_date);
doesn't work.
Why does the order of the items make a difference?
Thanks,
Ken 3 2378
"none" <""krwl\"@(none )"> wrote in message
news:ML******** ************@rc n.net... Hello:
Using PHP 4.3.11
The line: $strDate = preg_split('/[\.\/-]/', $my_date); works to break apart a date in the form mm/dd/yyyy or mm.dd.yyyy or mm-dd-yyyy but the line: $strDate = preg_split('/[\/-\.]/', $my_date); doesn't work.
Why does the order of the items make a difference?
In a regular expression character class definition (the bit in the []s), a
hyphen denotes a range of characters, so [a-z] will match all lowercase
letters of the alphabet, and [0-9] will match all numbers from 0 to 9. If
you escape your hyphen, it doesn't matter where you put it in your class.
$strDate = preg_split('/[\/\-\.]/', $my_date);
Thanks,
Ken
hope that helps!
dave
"d" <d@example.co m> wrote: In a regular expression character class definition (the bit in the []s), a hyphen denotes a range of characters, so [a-z] will match all lowercase letters of the alphabet, and [0-9] will match all numbers from 0 to 9. If you escape your hyphen, it doesn't matter where you put it in your class.
$strDate = preg_split('/[\/\-\.]/', $my_date);
Absolutely right. Also, this is rather trivial, but you shouldn't need to
escape the . in a character class, it's only a token when used outside a
character class. When inside a character class, the dot as well as
quantifiers (like *, ? etc.) are interpreted as literals.
Allen
Al13n wrote: In a regular expression character class definition (the bit in the []s), a hyphen denotes a range of characters, so [a-z] will match all lowercase letters of the alphabet, and [0-9] will match all numbers from 0 to 9. If you escape your hyphen, it doesn't matter where you put it in your class.
$strDate = preg_split('/[\/\-\.]/', $my_date); Absolutely right. Also, this is rather trivial, but you shouldn't need to escape the . in a character class, it's only a token when used outside a character class. When inside a character class, the dot as well as quantifiers (like *, ? etc.) are interpreted as literals.
Allen and Dave:
Thanks very much for your help. I'm surprised that /[\.\/-]/ worked at
all! A better way to have written it would have been: #[./\-]# which
works great.
Thanks, again.
Ken This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peter |
last post by:
L.S.
I am trying to cut a string into substrings. The string at hand looks
something like this:
$data='one|two|three|four\nfive|six|seven|eight'; //observe the chr(10) in
the middle
I would like to have this split two times. Once to give me the two
'sentences' 'one|two|three|four' and 'five|six|seven|eight'. Then, each of
|
by: Sims |
last post by:
Hi,
I need some help to split data using regular expression
Consider the string
'1,2,3', I can split it using, preg_split("/,/", '1,2,3') and i correctly
get =1, =2,=3.
Now if i have
|
by: voipcanada |
last post by:
is there any thing we can write to keep the right txt to the = sign in
the preg_split. from the following lines
DST-NUMBER-IN=0033512877596, DST-NUMBER-OUT=98751#33512877596,
DST-NUMBER-BILL=0033512877596
i only want 0033512877596, 98751#33512877596, 0033512877596
|
by: der |
last post by:
Hello all,
I've a question about order of evaluations in expressions that have && and
|| operators in them.
The question is: will the evalution go left-to-right, no matter what -- even
if the || operator is before the && operator? e,g,
In an expression like a = (z>x) || (x<0) && (z-y>9);
is it guaranteed that z>x will be checked first?
|
by: mdh |
last post by:
May I ask the group the following: (Again, alas , from K&R)
This is part of a function:
while ( ( array1 = array2 ) != '\0' ); /* etc etc */
Is this the order that this is evaluated?
-> array2 is assigned to array1 ....???? the reason being it is
| |
by: chadsmith76 |
last post by:
hello,
I have listings with coordinates, i would like to do ORDER BY and
display listings with coords first. If they don't have coords the value
is blank and the coords go both positive and negative values. So i
tried an "ORDER by l_xcoord HAVING l_xcoord<>0" but this is acting like
a WHERE statement removing all results with no coords. I tried GROUP BY
as well but same results...
So the question is how can i display all results with...
|
by: tiggman |
last post by:
Why preg_split works only if the char # before the delimiter is 21 or less?
example php code:
=============
$right = "{Hello Im very aaaaaa {cool|not cool}}";
print $right."<br>";
$pattern = '/({(?:+(?:"*"|\'*\')?)+})/';
$snip_array = preg_split($pattern, $right, -1, PREG_SPLIT_DELIM_CAPTURE);
print_r($snip_array);
============
If I change $right = "{Hello Im very aaaaa {cool|not cool}}"; the
|
by: Jeroen |
last post by:
Hi all,
I've got a very specific question about the evaluation order in C++.
Assume some kind of custom array class, with an overloaded subscript
operator. In the following code:
{
my_array a, b, c;
a = b + c;
|
by: mark1491 |
last post by:
I am trying to split a string into sentences with preg_split, but I would like it to not split initials.
Examples:
Mark H. Doolittle is my name. What is yours. ( I don't want it to split the middle initial, but want to split after 'name')
The company is is called H.R. Block. They are a good company. ( I don't want it to split after 'H', 'R')
Here is the code i have, but it causes a split at every period. can someone help me out, im...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |