问题
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
回答1:
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));
回答2:
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)); ?>
来源:https://stackoverflow.com/questions/3483422/replace-entites-in-rawurlencode-i-e-lt-gt-quot