How would you do a code-escape in PHP?
I have a huge list of stuff for a glossary ( about 17 pages worth ) that I have to put into an X开发者_Python百科ML file. So I decided I'd use php to make it. My code works, except where ALL the XML code is, it doesn't show because it's trying to render it. Help?
$arg=explode("\n", $strang);
echo count($arg);
for ($i=0;$i<=count($arg);$i=$i+3)
{
echo "<word id='" . $arg[$i+1] . "'>";
echo "<desc>" . $arg[$i] . " - " . $arg[$i+2] . "</desc>";
echo "<pic></pic>";
echo "<audio></audio>";
}
I assume by render it you mean in your browser? If so, you'll need to escape the characters so they will be interpreted literally rather than as markup.
Check out htmlspecialchars
and htmlentities
use CDATA construction:
echo "<desc><![CDATA[" . $arg[$i] . " - " . $arg[$i+2] . "]]></desc>";
If this is your entire script, fastest way would probably be to swap all of the <'s with <
$arg=explode("\n", $strang);
echo count($arg);
for ($i=0;$i<=count($arg);$i=$i+3)
{
echo "<word id='" . $arg[$i+1] . "'>";
echo "<desc>" . $arg[$i] . " - " . $arg[$i+2] . "</desc>";
echo "<pic></pic>";
echo "<audio></audio>";
}
精彩评论