替换 rawurlencode 中的实体,即 < > ”

发布于 2024-09-14 11:59:08 字数 1431 浏览 1 评论 0 原文

我有以下代码

<a href="snippet:add?code=<?php echo rawurlencode($snippet->snippet_content); ?>Save snippet</a>

'$snippet = &lt;a rel=&quot;nofollow&quot; href=&quot;http://digg.com/submit?phase=2&amp;url=&lt;?php the_permalink(); ?&gt;&quot; title=&quot;Submit this post to Digg&quot;&gt;Digg this!&lt;/a&gt;'

如何让 rawurlencode 替换“&lt”;到“<”?

提前非常感谢

rob

了更新

按照下面海报的建议进行

<?php echo rawurlencode(html_entity_decode($snippet->snippet_content)); ?>

,谢谢修复了更改 <到“<”但在整个片段中插入 \ ,

<a rel=\"nofollow\" href=\"http://delicious.com/post?url=<?php the_permalink(); ?>&title=<?php echo urlencode(get_the_title($id)); ?>\" title=\"Bookmark this post at Delicious\">Bookmark at Delicious</a>

我正在寻找的输出没有反斜杠以及

<a rel="nofollow" href="http://delicious.com/post?url=<?php the_permalink(); ?>&title=<?php echo urlencode(get_the_title($id)); ?>" title="Bookmark this post at Delicious">Bookmark at Delicious</a>

干杯抢劫

固定

感谢所有发布者!

<?php echo rawurlencode(htmlspecialchars_decode(stripslashes($snippet->snippet_content))); ?>

很有魅力,

非常感谢罗布

I have the following code

<a href="snippet:add?code=<?php echo rawurlencode($snippet->snippet_content); ?>Save snippet</a>

where

'$snippet = <a rel="nofollow" href="http://digg.com/submit?phase=2&url=<?php the_permalink(); ?>" title="Submit this post to Digg">Digg this!</a>'

How could I get rawurlencode to replace "<"; to a "<"?

Many thanks in advance

rob

updated

using

<?php echo rawurlencode(html_entity_decode($snippet->snippet_content)); ?>

as suggested by the posters below, thankyou fixes the changing < ; to "<" but inserts \ throughout the snippet

<a rel=\"nofollow\" href=\"http://delicious.com/post?url=<?php the_permalink(); ?>&title=<?php echo urlencode(get_the_title($id)); ?>\" title=\"Bookmark this post at Delicious\">Bookmark at Delicious</a>

the output I'm seeking is without the backslashes aswell

<a rel="nofollow" href="http://delicious.com/post?url=<?php the_permalink(); ?>&title=<?php echo urlencode(get_the_title($id)); ?>" title="Bookmark this post at Delicious">Bookmark at Delicious</a>

cheers rob

FIXED

Thankyou to all who posted!

<?php echo rawurlencode(htmlspecialchars_decode(stripslashes($snippet->snippet_content))); ?>

works a charm,

many thanks rob

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痕至 2024-09-21 11:59:08

rawurlencode() 与转换无关到/从 html 编码。它执行 URL 编码。要解码的匹配函数是 rawurldecode(),但同样,这不是您在这里寻找的。

< 编码是 html 编码。要处理这个问题,您需要 html_entity_decode() 进行解码或 htmlentities()< /a> 进行编码。

上述函数集的基本用法是:

$urlEncodedStr  = rawurlencode($str);
$urlDecodedStr  = rawurldecode($str);
$htmlEncodedStr = htmlentities($str);
$htmlDecodedStr = html_entity_decode($str);

要将它们组合在一起,您需要进行一些组合:

$urlEncodedHtmlDecodedStr  = rawurlencode(html_entity_decode($str));

rawurlencode() has nothing to do with converting to/from html-encoding. It performs URL encoding. The matching function to decode is rawurldecode(), but again, that is not what you're looking for here.

The < encoding is html-encoding. To handle that, you want html_entity_decode() to decode or htmlentities() to encode.

Basic usage for the above sets of functions is:

$urlEncodedStr  = rawurlencode($str);
$urlDecodedStr  = rawurldecode($str);
$htmlEncodedStr = htmlentities($str);
$htmlDecodedStr = html_entity_decode($str);

To combine them together you would do some combination:

$urlEncodedHtmlDecodedStr  = rawurlencode(html_entity_decode($str));
溺渁∝ 2024-09-21 11:59:08

您应该使用 html_entity_decode()函数< 转义为 <

但由于这是一个 URL 参数,因此您需要随后调用 rawurlencode(),即

<?php echo rawurlencode(html_entity_decode($snippet->snippet_content)); ?>

You should use the html_entity_decode() function to escape a < to <.

But since this is a URL argument, you need to call rawurlencode() afterward, i.e.

<?php echo rawurlencode(html_entity_decode($snippet->snippet_content)); ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文