dongshang6790 2014-07-02 01:09
浏览 447

将当前页面网址中的“+”替换为“%2B”或空格

I have a URL generated via form submission with passed variables. I won’t go into detail but the ‘+’ in the URL breaks the system, so I would like to replace it with ‘%2B’.

However, every method I have tried so far has not worked. I have tried the various PHP URL decode methods and none of them work, since they replace other characters in the URL which again breaks it.


The URL looks like this:

www.domain.com/catalog/search.php?sort_by=relevance&some_filter%5B%5D=filter+term


I have also tried getting the current page URL and using str_ireplace to replace the ‘+’ characters with regular spaces or ‘%2B’, all to no avail.

I would appreciate any help!
Thanks

  • 写回答

1条回答 默认 最新

  • dtrphb5597 2014-07-02 01:11
    关注

    If you're using php, try urlencode() and urldecode()

    http://www.php.net/manual/en/function.urlencode.php

    It will save you the headache of replacing the characters (which are then replaced).

    Here is a more complete example close to your use case.

    <?php
    
    $foo = str_replace('+','%2B', 'www.domain.com/catalog/search.php?sort_by=relevance&some_filter%5B%5D=filter+term');
    
    echo urldecode($foo);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块