0
4

2 に答える 2

1

The problem isn't with html_entity_decode(). The problem is that SimpleXML is treating the contents of the <text> element as XML instead of text. By default, SimpleXML compresses empty elements (<a></a> to <a />). One way to get around this is to import the SimpleXML object into a DOM object, and use the LIBXML_NOEMPTYTAG option when saving the output. The problem with this option is that any <br /> elements will be output as <br></br>.

The simpler alternative is to use a different response format from the API. I would suggest using the json response format and use the json_decode() function to parse the response.

于 2009-12-11T17:02:08.477 に答える
1

これは奇妙な出力ではなく、有効な XML です。空のタグがある場合、XML では、HTML や XHTML では常に有効であるとは限らない短い終了構文を使用できます。

<foo></foo>
<foo />

このhtml_entity_decode();関数は、次のような html エンティティを変換します。

&gt; converts to
>

xml フラグメントを後処理し、適切な HTML に変換する必要があります。これを行う最も簡単な方法は、DomDocumentAPI を使用することです。

$foo = new DomDocument();
$foo->loadHtml('<p> Testing <a href="" /> </p>');   
echo $foo->saveHtml();

これは XML フラグメントを取得し、それを HTML ドキュメントに変換します。これには、すべての自己終了タグの修正が含まれます。の内容を解析する必要がありますが<body/>、すべての自己終了タグを自分で修正するよりもはるかに簡単です。

于 2009-12-11T17:03:59.817 に答える