duanmao1975 2015-10-05 10:34
浏览 16
已采纳

替换PHP变量中的部分URL

I am using PHP to set the current URL as a variable using

$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

This would echo the string:

http://www.example.com/landing-page-demo/

I would like to replace the 'landing-page' part of the string with 'confirmation-page' and then save this updated URL as another variable.

I was thinking of using str replace, is this the most ideal method of doing this? Not sure how to approach the problem

  • 写回答

3条回答 默认 最新

  • doushanlv5184 2015-10-05 10:36
    关注

    Indeed, short of knowing regular expressions, str_replace will do the trick.

    Perform str_replace on $_SERVER['REQUEST_URI']

    Example:

    $url = 'http://' . $_SERVER['SERVER_NAME'] . str_replace("landing", "confirmation", $_SERVER['REQUEST_URI']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题