Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你能帮我解决这个问题吗,一个正则表达式语法来执行以下操作
例如 1 如果它以 //host/data/user/temp/data.text 开头,则希望将其设为“file://host/data/user ...”
示例:对于 2,如果它以 Google.com 开头,我想将其设为“html://Google.com”
Try this. $subject = 'filename'; //$subject = '//filename'; if(preg_match("/^\/\//", $subject)){ //$newstring= preg_replace("/^\/\//", "file://", $subject); $newstring= "file:".$subject; }else{ $newstring= "http://".$subject; }