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.
リンクのリストがあり、そのうちのいくつかには http:// ではなく http:/ が含まれていますが、http:// も存在する可能性があり、1 つの / を複数に置き換えるとパスが変更される可能性があるため、http:/ を検索できません。 ..
(ftp|http(s)):/ を (ftp:http(s)):// に変更する方法を教えてください。
これは機能するはずです(二重置換なし):
<? echo preg_replace("#(http|ftp|https):/([^/])#", "$1://$2", 'http://www.google.com'); echo "<br>"; echo preg_replace("#(http|ftp|https):/([^/])#", "$1://$2", 'http:/www.google.com'); ?>
これは、二重スラッシュがない場合にのみ置換を行います。