1
我是一個PHP中的完全新手,所以如果我的問題看起來很幼稚,那麼提前很抱歉。Cloudflare插件preg_replace改進
有一個插件(actuallly非常流行的CloudFlare SSL WordPress的),這是指用於轉換HTTP鏈接到https,它看起來像:
前:
<link rel="alternate" type="application/rss+xml" title="A B » Feed" href="http://site.biz/feed/" />
後:
<link rel="alternate" type="application/rss+xml" title="A B » Feed" href="//site.biz/feed/" />
這裏是它做了這樣的代碼:
if (is_null($content_type) || substr($content_type, 0, 9) === 'text/html') {
// replace href or src attributes within script, link, base, and img tags with just "//" for protocol
$re = "/(<(script|link|base|img|form)([^>]*)(href|src|action)=[\"'])https?:\\/\\//i";
$subst = "$1//";
$return = preg_replace($re, $subst, $buffer);
一切是除了良好的事實,這個插件是無法處理這樣的鏈接:
<div class="dslc-modules-section " style="background-color:rgb(14, 134, 219);background-image:url();background-image:url(http://site.biz/wp-content/uploads/2016/07/CloudPatches.jpg);background-position:center center;background-size:cover;padding-bottom:0px;padding-top:0px;">
有沒有人對如何提高這部分代碼,使之更加完美的想法?
上面提供的代碼就是我們通過查看代碼看到瀏覽器),因此,我們不能只是編輯它。內容是動態生成的。 –
只需使用str_replace('http://','https://',$ content_type)? –
此解決方案無法正常工作( –