Reputation: 6852
I have this string that used with simple html parser and something like this
<b>Atmosp'Hair, Caroline Michellod</b><i> in <a href="1" target="_top">Leytron</a></i>, Einzelunt., <a href="1" target="result">+++</a>, <a href="google.com" target="_blank">CHE-137.645.261</a><a href="pdf" target="_blank">Download pdf</a>
<b>Bar La Gouttière, Y. Maret</b><i> in <a href="http://www.example.com">Dolor</a><a href="2" target="_top">Martigny</a></i>, Einzelunt., <a href="2" target="result">+++</a>, <a href="yahoo.com" target="_blank">CHE-112.712.556</a><a href="http:/wwww.coocc.com">Doloo</a>
<b>Catherine Michellod</b><i> in <a href="3" target="_top">Bagnes</a></i>, Einzelunt., <a href="3" target="result">+</a>, <a href="bing.com" target="_blank">CHE-111.755.770</a><a href="pdf" target="_blank">Download pdf</a>
What i need is to get new array from this and display it on page to be like this
<a href="google.com" target="_blank">CHE-137.645.261</a>
<a href="yahoo.com" target="_blank">CHE-112.712.556</a>
<a href="bing.com" target="_blank">CHE-111.755.770</a>
I have tried to find attribute _blank, but there is sometime another link with that attribute, also have tried to find nt child but there is sometimes another a tag. A lot of bad HTML, only thing that is unique is that a href inner html starts with CHE
Upvotes: 1
Views: 54
Reputation: 59701
Just use preg_match_all()
to get all matches, e.g.
<?php
preg_match_all("/<[^>]*>CHE[^<]*<[^>]*>/", $str, $m);
print_r($m[0]);
?>
output:
Array
(
[0] => <a href="google.com" target="_blank">CHE-137.645.261</a>
[1] => <a href="yahoo.com" target="_blank">CHE-112.712.556</a>
[2] => <a href="bing.com" target="_blank">CHE-111.755.770</a>
)
Upvotes: 1