PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Nov 20, 2017 4:25 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Jan 24, 2016 5:14 am 
Offline
Forum Newbie

Joined: Sun Jan 24, 2016 4:40 am
Posts: 1
Can anybody explain me about the following code.
The following code
<?php
$a = 'first line
second line
';
$b = '/l...$/';
$match = preg_match_all($b,$a,$matches);

print_r($matches);

?>
is showing the output

Array ( [0] => Array ( ) )

instead of
Array ( [0] => Array ( [0] => line ) )

But the following code

<?php
$a = 'first line
second line
';
$b = '/l....$/';
$match = preg_match_all($b,$a,$matches);

print_r($matches);

?>
is showing
Array ( [0] => Array ( [0] => line ) )
instead of

Array ( [0] => Array ( ) )
Can anyone explain me why it is working in reverse order in my computer?


Top
 Profile  
 
PostPosted: Sun Jan 24, 2016 5:36 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6579
Location: WA, USA
Muhammad Zeeshan wrote:
The following code
<?php
$a = 'first line
second line
';
$b = '/l...$/';
$match = preg_match_all($b,$a,$matches);

print_r($matches);

?>
is showing the output

Array ( [0] => Array ( ) )

instead of
Array ( [0] => Array ( [0] => line ) )

$ only matches the end of a line if you pass the /m flag.
Code:
/l...$/m


Muhammad Zeeshan wrote:
But the following code

<?php
$a = 'first line
second line
';
$b = '/l....$/';
$match = preg_match_all($b,$a,$matches);

print_r($matches);

?>
is showing
Array ( [0] => Array ( [0] => line ) )
instead of

Array ( [0] => Array ( ) )

It isn't doing that... You sure you got that right?


Top
 Profile  
 
PostPosted: Wed May 11, 2016 3:31 pm 
Offline
Forum Newbie

Joined: Wed May 11, 2016 3:14 pm
Posts: 3
The one with 3 dots is matching line, the with 4 isn't. At least not on regex101.com

/l...$/m matches "line" (on the first line)
/l...$/ matches "line" (on the second line)

And:
/l....$/m and /l....$/ matches nothing, so indeed, are you sure you got that right?

[edit] wow old thread nvm [/edit]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group