我正在從經典ASP(VBScript)到PHP翻譯功能。我做了一個嘗試,但我不確定我的代碼是否正確,所以我想問問其他人。vbScript到PHP轉換:正則表達式來刪除HTML標記
下面的vbscript函數包含一個刪除html標籤的正則表達式。 (正則表達式來自http://regexplib.com)。這裏的VBScript代碼翻譯:
Function StripTags(ByVal szString,ByVal szTags)
If szTags = "" Then szTags = "[a-zA-Z]+"
Dim regEx : Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
' tag to remove (based on http://regexplib.com/REDetails.aspx?regexp_id=211)
regEx.Pattern = "</?("+szTags+")(\s+\w+=(\w+|""[^""]*""|'[^']*'))*\s*?/?>"
StripTags = regEx.Replace(szString, "")
Set regEx = Nothing
End Function
我發現PHP有一個內置的函數調用用strip_tags($ szString)。這個函數是否和上面的代碼一樣?
我還發現這款主板更復雜的PHP HTML去除功能,但我不知道,如果它做同樣的事情:
function StripTags($szString,$szTags){
$szString = preg_replace(
array(
// Remove invisible content
'@<head[^>]*?>.*?</head>@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
'@<object[^>]*?.*?</object>@siu',
'@<embed[^>]*?.*?</embed>@siu',
'@<applet[^>]*?.*?</applet>@siu',
'@<noframes[^>]*?.*?</noframes>@siu',
'@<noscript[^>]*?.*?</noscript>@siu',
'@<noembed[^>]*?.*?</noembed>@siu',
// Add line breaks before and after blocks
'@</?((address)|(blockquote)|(center)|(del))@iu',
'@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
'@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
'@</?((table)|(th)|(td)|(caption))@iu',
'@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
'@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
'@</?((frameset)|(frame)|(iframe))@iu',),
array(
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
"\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
"\n\$0", "\n\$0",
),
$szString);
$szString = strip_tags($szString);
return;}
誰能告訴我,如果上面的PHP函數做同樣的作爲VBscript功能的東西?
坦白說,我不知道你通過改變PHP定界符允許ASP VBSCRIPT的人是什麼意思。我不熟悉那個......你能詳細說明一下嗎? –
在這種情況下,在Apache上安裝VBScript支持不是一種選擇。 –