<?php
$tagfield = 'Tag Tag2, Tag3 "Tag" "A Tag" "with \" escaped \\" quote" "\slash"';
preg_match_all('~(?|"((?:[^\\\\"]+|\\\\.)*)"|([^ ,]+))~', $tagfield, $m);
var_export($m[1]);
echo "\n";
print_r($m[1]);
echo "\n---\n";
$tagfield = 'Tag Tag2, Tag3 "Tag" "A Tag"';
preg_match_all('~(?|"([^"]+)"|([^ ,]+))~', $tagfield, $m);
var_export($m[1]);
echo "\n";
print_r($m[1]);
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- array (
0 => 'Tag',
1 => 'Tag2',
2 => 'Tag3',
3 => 'Tag',
4 => 'A Tag',
5 => 'with \\" escaped \\" quote',
6 => '\\slash',
)
Array
(
[0] => Tag
[1] => Tag2
[2] => Tag3
[3] => Tag
[4] => A Tag
[5] => with \" escaped \" quote
[6] => \slash
)
---
array (
0 => 'Tag',
1 => 'Tag2',
2 => 'Tag3',
3 => 'Tag',
4 => 'A Tag',
)
Array
(
[0] => Tag
[1] => Tag2
[2] => Tag3
[3] => Tag
[4] => A Tag
)
preferences:
106.76 ms | 403 KiB | 123 Q