开发者

Why is rawurlencode() in PHP adding additional escape characters to ampersands?

开发者 https://www.devze.com 2023-02-14 13:30 出处:网络
I think I\'m missing something obvious here but it is driving me crazy and I can\'t figure it out.I\'m developing a WordPress plugin an开发者_StackOverflow中文版d part of it needs to take the WordPres

I think I'm missing something obvious here but it is driving me crazy and I can't figure it out. I'm developing a WordPress plugin an开发者_StackOverflow中文版d part of it needs to take the WordPress post title and send that to a RESTful web service to do something else. So of course I want to rawurlencode() the post title since who knows what text might be in there. However, for some reason the output I'm getting has extra escape characters and I have no idea where they are coming from (and it's causing problems with the web service I'm calling obviously).

My code is fairly straight forward:

$topic = get_the_title($post_id);
$curl_post_fields = 'name=' . rawurlencode( $topic );  

Yet when I print the output of those two strings I get:

topic=a & b
name=a%20%26%23038%3B%20b

Whereas I would expect the URL encoded string to be

name=a%20%26%20b

I have no idea where that extra %23038%3B could be coming from. If I'm reading the encoding on that correctly it translates to #038; but I still don't know where it's coming from.


There seems to be a html encoding in between as well, instead of &, & is in the encoded string. Probably because & has to be escaped in html, and the get_title function escapes this using html_special_chars or something like that.


I had some problems with that when i used an older php version

0

精彩评论

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