Reputation: 1447
Im using get_file_contents to create a Array. Below you can see a var_dump
of my Array.
How I get this Array?
function remap_alternating(array $values) {
$remapped = array();
for($i = 0; $i < count($values) - 1; $i += 2) {
$remapped[trim($values[$i], ": ")] = trim($values[$i + 1], " ");
}
return $remapped;
}
$mapped = remap_alternating($matches[0]);
foreach($mapped as $key => $val) {
}
Result of: var_dump($mapped);
array(32) {
["<td valign="top" class="maintext"><strong>Age:</strong></td>"]=>
string(137) "<td class="graytext">21 Years. </td>"
["<td valign="top"><strong>Ethnicity:</strong></td>"]=>
string(122) "<td class="graytext">Black</td>"
["<td valign="top" class="maintext"><strong>Location:</strong></td>"]=>
string(152) "<td class="graytext">Dubai, United Arab Emirates</td>"
My question is how can I remove HTML code from this Array?
Upvotes: 1
Views: 2139
Reputation: 31614
Easiest way is with strip_tags
$clean = array();
foreach($array as $key => $val) {
$clean[strip_tags($key)] = strip_tags($val);
}
EDIT
In your function, change your line to this
$remapped[strip_tags(trim($values[$i], ": "))] = strip_tags(trim($values[$i + 1], " "));
You don't even need my snippet then
Upvotes: 4