duang5049 2015-06-26 23:25
浏览 26
已采纳

如何在第一个后更换所有问号

So, a lot of my form systems redirect back to the previous page, although, they display a message in the process. The way I display a message is by simply using ?message=messageCode in the URL.

However, if they use the form from a page that already has a query string, it adds a second query string, messing everything up.

Example: if I were to login from the navigation bar, on the URL "mywebsite.com/something?message=1", it would log in, but redirect to "mywebsite.com/something?message=1?message=2"

This results in no message being displayed.

What I am asking here is, how could I change all of the question marks AFTER the first question mark, to and signs?

Example: From: mywebsite.com/page?blah=1?something=2?hi=3 To: mywebsite.com/page?blah=1&something=2&hi=3

I have searched around, as well as tried some methods of my own, but nothing seems to work properly.

  • 写回答

2条回答 默认 最新

  • dongluo1853 2015-06-26 23:32
    关注

    Use it like below:-

    <?php
       $str = 'mywebsite.com/something?message=1?message=2';
       $pos = strpos($str,'?'); //check the last occurrence of ?
       if ($pos !== false) {
           $str = substr($str,0,$pos+1) . str_replace('?','&',substr($str,$pos+1));// replacement of ? to &
       }
      echo $str;
    ?>
    

    Output:- https://eval.in/388308

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法