php 数组 strip_tags 并取消设置
大家好,我有一个关于 strip_tags 函数的问题。 我有一个这样的html文档。
<!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>
这个php脚本的
<?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>";
?>
问题是它不会取消设置空变量(从strip_tags返回)并回显类似这样的内容。以下是否意味着它回显空字符串? 任何意见或帮助将不胜感激。提前感谢
<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] =>
)
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] =>
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你只是逐一数数并回响。如果您想跳过空,请在循环中执行以下操作:
希望我正确理解您的意思。
You're just counting through and echoing for each. If you want to skip empty, do something like this in your loop:
Hope I understood you correctly.
对于您正在做的事情来说,这段代码看起来非常巴洛克。下面的代码能满足您的需要吗?
This code seems incredibly baroque for what you are doing. Does the following code do what you need?
我可能是错的......但是......
当你分解这些行时,我很确定它们有一个隐式的 /n 这意味着它们永远不会为空。另一种选择是:
I'm probably wrong... but...
When you explode these lines, I'm pretty sure they have an implicit /n that is going to mean they're never empty. An alternative, though it is a little slower, would be: