Jump to content

matching a pattern on each line.


the_butcher

Recommended Posts

The [tt]/m[/tt] modifier puts the pattern in multi-line mode, which allows ^ to match after a new line, and $ before. Modifiers are placed after the last delimiter, e.g.: [tt]/pattern/m[/tt].

A more extensible, and arguably cleaner solution follows:

[code]
<pre>
<?php

$tests = array(
'"etc etc","etc etc"',
'"etc2","etc 22"',
'"12312","etc.. etc.."'
);

foreach ($tests as $test) {
$array = preg_split('/[",]/', $test, -1, PREG_SPLIT_NO_EMPTY);
print_r($array);
}

?>
</pre>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.