【发布时间】:2018-09-03 05:16:00
【问题描述】:
我有一个 php 变量,其中包含这样的 url 字符串:
$url1 = 'http://test1.com/';
$url2 = 'https://test2.com';
$url3 = 'http://test3.com/';
我想用特定字符串替换 http 或 https 前缀,并且仅当字符串变量在字符串末尾包含破折号时才删除末尾的破折号,例如:
$url1 = 'stackoverflow://test1.com';
$url2 = 'stackoverflow://test2.com';
$url3 = 'stackoverflow://test3.com';
【问题讨论】:
-
你有没有尝试过?分享您的代码。
-
@EmptyBrain 不,我不知道该怎么做
-
@EmptyBrain 快捷方式
https? -
echo preg_replace ('/https|http/','stackoverflow','http://test1.com/'); -
@EmptyBrain 如果我有这样的 url
https://sdasdahttpol.com/它将替换 https 之后的 http,以及如何删除最后一个字符串字符中的/如果只有字符串最后一个字符是 @987654327 @