ehime
ehime

Reputation: 8375

PHP equivelant of Perl line?

Can someone tell me if I'm right with this? I'm trying to port a fairly massive perl script into OO-PHP, and have been stuck on a few things, this is one of them and just need some confirmation if I'm doing it right, the perl code is:

my ($command,@args)=split(/\n/,$message);

is this the same as doing this in PHP?

list($command, $args[]) = preg_split('/\n/', $message);

Upvotes: 3

Views: 130

Answers (1)

user142162
user142162

Reputation:

No. What you're trying to do is invalid and will not work. The equivalent PHP code would be:

$args = preg_split('/\n/', $message);
$command = array_shift($args);

The use of preg_ functions should be only used when necessary, so you could actually replace the preg_split with:

explode("\n", $message);

Upvotes: 8

Related Questions