1

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?

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.