小さい頃はエラ呼吸

いつのまにやら肺で呼吸をしています。


VBScriptで簡易的なhtmlspecialchars関数を実装する

はじめに

VBScriptで、PHPのhtmlspecialcharsメソッド(特殊文字を HTML エンティティに変換する)を実装してみました。

Function htmlspecialchars(Byref string, Byref quote_style)
  Dim tmp
  tmp = string
  tmp = Replace(tmp, "&", "&")
  tmp = Replace(tmp, "<", "&lt;")
  tmp = Replace(tmp, ">", "&gt;")
  
  If quote_style = "" OR quote_style = "ENT_COMPAT" Then
    tmp = Replace(tmp, """", "&quot;")
  ElseIf quote_style = "ENT_QUOTES" Then
    tmp = Replace(tmp, """", "&quot;")
    tmp = Replace(tmp, "'", "&#039;")
  ElseIf quote_style = "ENT_NOQUOTES" Then
    ' NOP
  End If
  
  htmlspecialchars = tmp
End Function

charset、double_encodeパラメタについては、実装していません。

参考サイト


最速攻略 VBScriptサンプル大全集
結城 圭介
技術評論社
売り上げランキング: 17109
おすすめ度の平均: 4.0
4 最速攻略に偽りなし。
4 分かりやすいと思いますよ
5 ステップアップ
3 ユーズドで買う人は要注意
5 VBScriptが使いこなせる本