php array strip_tags and unset
Posted
by
teo6389
on Stack Overflow
See other posts from Stack Overflow
or by teo6389
Published on 2011-12-01T00:50:32Z
Indexed on
2011/12/01
1:52 UTC
Read the original article
Hit count: 140
hello everybody i have a question regarding strip_tags function. i have an html document like that.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>er</p>
</body>
</html>
and this php script
<?php
$file = "ht.html";
$fp = fopen($file, "r");
$data = fread($fp, filesize($file));
fclose($fp);
$output = str_replace("\t|\t", "|", $data);
$outputline = explode("\n", $output);
$lexeisline=count($outputline);
for ($i = 0; $i < $lexeisline; $i++){
$outputline[$i]=strip_tags($outputline[$i]);
if (empty($outputline[$i])){
unset($outputline[$i]);
}
}
$outputline = array_values($outputline);
$lexeisline=count($outputline);
echo "<p>";
for ($i = 0; $i < $lexeisline; $i++){
echo ($outputline[$i])."<br />";
}
echo "</p>";
?>
the problem is that it does not unset the empty vars(which are returned from the strip_tags) and echos something like this. does the following means that it echos empty strings? any opinion or help will be very appreciated. Thanx in advance
<p>
<br />
<br />
<br />
<br />Untitled Document
<br />
<br />
<br />er
<br />
<br /></p>
@phpmeh
Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => Untitled Document
[5] =>
[6] =>
[7] => er
[8] =>
)
© Stack Overflow or respective owner