This is a direct translation of the code above with "content" populated for demo purposes:
<?php
$contents = '"cap":"foo" "cap":"wahey"';
if (preg_match_all('/"cap":"(.*?)"/', $contents, $matches, PREG_SET_ORDER)) {
var_dump($matches);
}
Output:
array(2) {
[0]=>
array(2) {
[0]=>
string(11) ""cap":"foo""
[1]=>
string(3) "foo"
}
[1]=>
array(2) {
[0]=>
string(13) ""cap":"wahey""
[1]=>
string(5) "wahey"
}
}
If you really want to do something with the result, for example. list it, try:
<?php
$contents = '"cap":"foo" "cap":"wahey"';
if (preg_match_all('/"cap":"(.*?)"/', $contents, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
echo $match[1] . "\n";
}
}
source
share