douyin7416
2015-07-13 12:10
浏览 98
已采纳

在两个斜杠之间替换字符串

I have to modify an URL like this:

$string = "/st:1/sc:RsrlYQhSQvs=/fp:1/g:3/start:2015-07-01/end:2015-07-30";

Namely, I want to delete st:1 with a regex. I used:

preg_replace("/\/st:(.*)\//",'',$string)

but I got

end:2015-07-30

while I would like to get:

/sc:RsrlYQhSQvs=/fp:1/g:3/start:2015-07-01/end:2015-07-30

Same if I would like to delete fp:1.

图片转代码服务由CSDN问答提供 功能建议

我必须修改这样的URL:

  $  string =“/ st:1 / sc:RsrlYQhSQvs = / fp:1 / g:3 / start:2015-07-01 / end:2015-07-30”; 
   
  
 

即,我想用正则表达式删除 st:1 。 我用过:

  preg_replace(“/ \ / st:(。*)\ //”,'',$ string)
    
 
 

但我得到

  end:2015-07-30 
   
 
 

我想得到:

  / sc:RsrlYQhSQvs = / fp:1 / g:3 / start:2015-07-01 / end:2015-07-30 
    
 
 

如果我想删除 fp:1 ,则相同。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • duanji1899 2015-07-13 12:14
    已采纳

    You need to add ? in your regex:-

    <?php
    
    $string = "/st:1/sc:RsrlYQhSQvs=/fp:1/g:3/start:2015-07-01/end:2015-07-30";
    echo preg_replace("/\/st:(.*?)\//",'',$string)
    
     ?>
    

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

    Based on this same you can do for next things also.

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(3条)

相关推荐 更多相似问题