开发者

replace entites in rawurlencode i.e. < > "

开发者 https://www.devze.com 2023-01-11 19:18 出处:网络
I have the following code <a href=\"snippet:add?code=<?php echo rawurlencode($snippet->snippet_content); ?>Save snippet</a>

I have the following code

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

where

'$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;'

How could I get rawurlencode to replace "&lt"; 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 &lt ; 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 se开发者_如何学运维eking 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


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 &lt; 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));


You should use the html_entity_decode() function to escape a &lt; 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)); ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号