0

I am working on a project and I am facing a problem that "span>" also prints in the start of text I tried to remove all the tags every thing gone finely except the one i mentioned above,

here is my php code

      <p>
        <?php
         $desc = $top_news['headline_des'];
         $aa = preg_replace( '/style=(["\'])[^\1]*?\1/i', '', $desc, 2 );
             if(strlen($top_news['headline_des'])>100)
                {
                $description = substr($aa, 1 ,850)."...";

                    }else{
                    $description = $aa;
                     }

                  echo strip_tags($description);
        ?>
    </p> 

here is the output

span >IPOR have the International Republican Institute (IRI) and the United States Agency for International....

4

4 回答 4

1

问题是substr($aa, 1 ,850)通话。substr从位置 0 开始,而不是 1,所以会发生这样的事情:

Input: <span>Foobar</span>
substr($input, 1, 850)
Output: span>Foobar</span>

substr愉快地切断第一个字符。因此,strip_tags不会将其识别span>为一个完整的标签,而只是将其单独放置。

修复:使用substr($aa, 0, 850).

于 2013-01-24T10:56:43.160 回答
0
$intro = ereg_replace("[</*>]", "", $intro);
于 2013-01-24T10:22:58.153 回答
0

您只能使用strip_tags 来删除标签

使用preg_replace

$desc = $top_news['headline_des'];
$search = array(
'@<style[^>]*?>.*?</style>@siU',
'@<[\/\!]*?[^<>]*?>@si'            
);

echo $pregReplacedContent = preg_replace($search, "", $aa);
于 2013-01-24T10:23:36.763 回答
0
 $text = preg_replace("/<.+?>/", "", $text);

像这样的东西应该删除变量中的任何标签$text

如果它不起作用,您应该检查要从中删除标签的初始文本是否格式正确。例如 aspan >不会被删除,因为它不是标签,但 a<span >会被删除而没有问题。

于 2013-01-24T10:34:39.827 回答