php rawurldecode不会产生传递给rawurlencode的相同字符串 [英] php rawurldecode doesn't produce same string passed to rawurlencode

查看:72
本文介绍了php rawurldecode不会产生传递给rawurlencode的相同字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在网站网址的URI分段中使用空格和括号(该分段用于数据库查询)。所以,我 rawurlencode()一个字符串,然后 rawurldecode()在接收页面中使用相同的字符串,但是不是完全一样。空格很好,但括号保留在其十六进制字符中。这完全搞乱了我的数据库查询。知道为什么 rawurldecode 没有生成传递给 rawurlencode()的精确字符串吗?



原始字符串=康普顿社区学院(CA)



编码字符串=

 康普顿%20Community%20College%20%28CA%29 

解码后的字符串的字元是

 字符串(38)康普顿社区学院(CA) 

在视图页面源中

 康普顿社区学院( CA) 

edit



好,所以显然这可能是Codeigniter的事情(我正在使用)。代码

 < a href ='<?php echo site_url('college /'。rawurlencode($ player ['学院'])); ?>’> 

生成 http:// localhost / ff / index的正确URL。 php / college / Compton%20Community%20College%20%28CA%29



在以下函数中,最终的URI段作为参数被接收

  function view_college($ college = FALSE)
{
if($ college === FALSE)
{//没有大学提供
redirect('');
}
$ college = rawurldecode($ college);

此时,该字符串已经处于上面显示的形式。因此,也许我正在搞砸,或者不能指望CI正确传递字符串。 :-(有想法吗?

解决方案

如果您不想使用ID(也许是出于SEO的原因),则可以添加另一个ID字段到db-Web url,然后写一个大学名称的Web安全版本...在您的示例中,它可能是 Compton-Community-College-CA 甚至小写。 p>

完整网址:

  http:// localhost / ff / index。 php / college / Compton-Community-College-CA 

CodeIgniter的URL帮助器具有出色的功能: url_title()


I need to be able to have spaces and parentheses in a URI segment of my site's URLs (the segment is used for DB queries). So, I rawurlencode() a string and then rawurldecode() the same string in the receiving page, however it's not entirely the same. The spaces are fine but parentheses are left in their hex char codes. Which completely messes up my database queries. Any idea why rawurldecode isn't producing the EXACT string which was passed to rawurlencode()?

the original string = Compton Community College (CA)

the encoded string =

  Compton%20Community%20College%20%28CA%29

a vardump of the decoded string is

  string(38) "Compton Community College (CA)"

in the view page source

  "Compton Community College &#40;CA&#41;"

edit

alright, so apparently this might be a Codeigniter thing (which I'm using). The code

<a href='<?php echo site_url('college/'.rawurlencode($player['college'])); ?>'> 

produces the correct url of http://localhost/ff/index.php/college/Compton%20Community%20College%20%28CA%29

The final URI segment is recieved as a parameter in the following function

function view_college($college = FALSE)
{
    if($college === FALSE)
    {//no college provided
        redirect('');
    }
    $college = rawurldecode($college);

And at this point the string is already in the form displayed above. So maybe I'm screwing something up or just can't expect CI to correctly pass the string. :-( Thoughts?

解决方案

If you don't want to use IDs (for SEO reasons maybe), you can add another field to the db - web url, and write a web-safe version of the college name... In your example it could be something like Compton-Community-College-CA or even lowercase.

Full url:

http://localhost/ff/index.php/college/Compton-Community-College-CA

CodeIgniter's URL Helper has a nice function for that: url_title().

这篇关于php rawurldecode不会产生传递给rawurlencode的相同字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆