gpt4 book ai didi

php 的 strip_tags() 不起作用

转载 作者:行者123 更新时间:2023-12-05 02:25:11 28 4
gpt4 key购买 nike

我正在尝试稍微调整一下 wordpress,但我的 php 级别为 0,所以我有点烂 :/

我想添加一个自定义的“发推文”按钮(我知道已经有无数这样的按钮了,我只是想自己做,为了好玩)

所以,我正在尝试这个:

<a href="http://twitter.com/home?status=<?php strip_tags(the_excerpt()) ?>" >tweet this</a>

the_excerpt() 返回 "<p> ... excerpt ... </p>"并且 strip_tags 函数不会剥离那些 <p>标签!

我做错了什么?

谢谢,抱歉,如果很明显。

最佳答案

您的问题是the_excerpt() 没有将其内容返回给strip_tags(),而是使用echo 直接输出。所以 strip_tags()(它需要前面的 echo 来做任何工作)不能做任何事情。

使用get_the_excerpt()相反(为清楚起见插入换行符,使用时删除):

<a href="http://twitter.com/home?status=
<?php echo strip_tags(get_the_excerpt()); ?>" >tweet this</a>

顺便说一下,我还要urlencode() 摘录,否则如果它包含"双引号或其他有趣的字符,你一定会遇到麻烦。

关于php 的 strip_tags() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2541694/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com