Reputation: 3243
I have an HTML in string, I am trying to extract it and put into variable.
HTML
<b>App name</b>
v1.1.5 by
<a href="#">Link</a>
<br>
some description of app -
<a href="#">options</a>
<br>
<small style="color:#666">By Android market</small>
My main problem is that some text are not warped by HTML tag, like v1.1.5 by
and some description of app
.
How do I get all text inside and out side tags and put them in array ? I have not tried any code cuz I dont know get the text of not warped by tag
Upvotes: 2
Views: 58
Reputation: 12168
Try strip_tags()
+ explode()
+ array_filter()
:
<?php
// header('Content-Type: text/plain');
$str = <<<HTM
<b>App name</b>
v1.1.5 by
<a href="#">Link</a>
<br>
some description of app -
<a href="#">options</a>
<br>
<small style="color:#666">By Android market</small>
HTM;
$buffer = array_filter(explode(PHP_EOL, strip_tags($str)));
var_dump($buffer);
?>
Output:
array(6) {
[0]=>
string(8) "App name"
[1]=>
string(9) "v1.1.5 by"
[2]=>
string(4) "Link"
[4]=>
string(25) "some description of app -"
[5]=>
string(7) "options"
[7]=>
string(17) "By Android market"
}
Upvotes: 3