简体   繁体   English

在php cURL中忽略@而不对其进行编码

[英]Ignore @ in php cURL without encoding it

I am sending an image and a tweet (text) to Twitter API as multipart/form-data. 我将图像和推文(文本)作为multipart / form-data发送到Twitter API。 The image starts with '@someimagefile' and works as expected. 图像以'@someimagefile'开头,并按预期工作。 The tweet text is something like, '@username hi.' 推文文字就像'@username hi'。 but fails because cURL tries to interpret @username as a file path and errors out. 但失败是因为cURL试图将@username解释为文件路径并输出错误。

See answer from Wang Bin: https://stackoverflow.com/a/9137917/922522 请参阅王斌的回答: https//stackoverflow.com/a/9137917/922522

While a work-around is to prefix the tweet text with a space so the @ isn't the first char, I was wondering if there was a better way to do this? 虽然解决方法是在推文文本前加上一个空格,所以@不是第一个字符,我想知道是否有更好的方法来做到这一点? Twitter does not allow the @ sign to be encoded as anything else, https://dev.twitter.com/discussions/6663 . Twitter不允许将@符号编码为其他任何内容, https://dev.twitter.com/discussions/6663

Is there a way to make cURL for PHP ignore the @ sign in the text (and not for the image)? 有没有办法让PHP的cURL忽略文本中的@符号(而不是图像)?

Have you tried encoding the "@" in the tweet? 你试过在推文中编码“@”吗?

str_replace('@', urlencode('@'), $tweet);

edit: I saw your the forum post you linked and I believe he's saying it needs to be percent encoded which is what urlencode does. 编辑:我看到你链接的论坛帖子,我相信他说它需要百分比编码,这是urlencode的作用。 Have you tried what I posted above? 你试过我上面发布的内容了吗? If not give it a shot. 如果不给它一个机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM