首先,我需要检查URL字符串,如果URL的协议是https,那么我需要http在PHP中替换.所以这个php函数的输入和输出必须是这样的:
Input -> https://example.com/example/https.php
Output-> http://example.com/example/https.php
Input -> http://example.com/example/https.php
Output-> http://example.com/example/https.php
Run Code Online (Sandbox Code Playgroud)
这将确保它位于字符串的开头,然后是 ://
$input = 'https://example.com/example/https.php';
echo preg_replace('/^https(?=:\/\/)/i','http',$input);
Run Code Online (Sandbox Code Playgroud)