しばらくインターネットを検索したところ、記号からHTML番号への変換を可能にするオンラインツールがたくさんあることがわかりましたが、その逆はできません。
HTML番号からシンボルに変換するためのツール/オンラインツール/PHPスクリプトを探しています
例えば:
& -> &
その後に戻る
& -> &
誰かがこれを知っていますか?
しばらくインターネットを検索したところ、記号からHTML番号への変換を可能にするオンラインツールがたくさんあることがわかりましたが、その逆はできません。
HTML番号からシンボルに変換するためのツール/オンラインツール/PHPスクリプトを探しています
例えば:
& -> &
その後に戻る
& -> &
誰かがこれを知っていますか?
次を使用してJavaで実行できます。
import org.apache.commons.lang.StringEscapeUtils
を使用してStringEscapeUtils.unescapeHtml(String str) method
例 出力:
System.out.println(StringEscapeUtils.unescapeHtml("@"));
@
System.out.println(StringEscapeUtils.unescapeHtml("€"));
-
System.out.println(StringEscapeUtils.unescapeHtml("–"));
€
あなた自身を転がしてください;)
PHPの場合:グーグル検索でhtmlentitiesとhtml_entity_decodeが見つかりました:
<?php
$orig = "I'll \"walk\" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a; // I'll "walk" the <b>dog</b> now
echo $b; // I'll "walk" the <b>dog</b> now
// For users prior to PHP 4.3.0 you may do this:
function unhtmlentities($string)
{
// replace numeric entities
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
// replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
$c = unhtmlentities($a);
echo $c; // I'll "walk" the <b>dog</b> now
?>
.NETの場合HTMLEncodeまたはHTMLDecodeを使用する単純なものを記述できます。例えば:
HTMLDecode
[Visual Basic]
Dim EncodedString As String = "This is a <Test String>."
Dim writer As New StringWriter
Server.HtmlDecode(EncodedString, writer)
Dim DecodedString As String = writer.ToString()
[C#]
String EncodedString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlDecode(EncodedString, writer);
String DecodedString = writer.ToString();
これらの数値のほとんどは、ASCIIまたはUnicodeの値であると私は信じています。したがって、必要なのは、その値に関連付けられている記号を調べることだけです。非ユニコードシンボルの場合、これは(pythonスクリプト)のように単純である可能性があります。
#!/usr/bin/python
import sys
# Iterate through all command line arguments
for entity in sys.argv:
# Extract just the digits from the string (discard the '&#' and the ';')
value = "".join([i for i in entity if i in "0123456789"])
# Get the character with that value
result = chr(value)
# Print the result
print result
次に、次のように呼び出します。
python myscript.py "&"
これはおそらく、phpまたは他の何かに非常に簡単に変換できます。
<?php
$str = "The string ends in ampersand: ";
$str .= chr(38); /* add an ampersand character at the end of $str */
/* Often this is more useful */
$str = sprintf("The string ends in ampersand: %c", 38);
?>
(私はphpを知らないのでここから取った!)。もちろん、これは「&」を38に変換するために変更する必要がありますが、phpを知っている人のための演習として残しておきます。