user3379482
user3379482

Reputation: 567

can't find preg matches for a string and sort them into array

I'm trying to find preg match_all for the ISBN for this lines:

<td itemprop="isbn">9789953278544</td></tr>
<td itemprop="isbn">9789953278535</td></tr>
<td itemprop="isbn">9789953278568</td></tr>

I've tried:

preg_match_all('|<td itemprop="isbn">(.+?)"</td></tr>|si', '<td itemprop="isbn">9789953278544</td></tr><td itemprop="isbn">9789953278535</td></tr><td itemprop="isbn">9789953278568</td></tr>', $tags, PREG_SET_ORDER);
echo $connect[1][0];
foreach ($tags as $tag) {
    echo $tag[1] . "<br>";
}

Upvotes: 1

Views: 67

Answers (1)

Sojan Jose
Sojan Jose

Reputation: 3238

try with this search pattern .

My code

<?php

preg_match_all('/<td itemprop="isbn">(.+?)<\/td><\/tr>/', '<td itemprop="isbn">9789953278544</td></tr><td itemprop="isbn">9789953278535</td></tr><td itemprop="isbn">9789953278568</td></tr>', $tags, PREG_SET_ORDER);

foreach ($tags as $tag) {
        echo $tag[1] . "<br>";
    }
?>

output

9789953278544<br>9789953278535<br>9789953278568<br>

Upvotes: 2

Related Questions