简单地说,我需要检查变量$ url中的字符串是否是一个简单的http,如果是,请用https替换它 - 但我无法使它工作 - 任何想法:preg_replace http with https
$url="http://www.google.com"; // example http url ##
$url_replaced = preg_replace('#^http://#','https://', $url); // replace http with https ##
干杯!
你俩在同一时间回答..所以卡罗获得的积分,因为他/她少.. –
只是要小心的URL不包含在它的另一个网址查询参数。例如: 'echo str_replace('http://','https://','http://foo.com?redirect=http://bar.com'); // https://foo.com?redirect = https:// bar.com' – lizlux