I have a source html document that has a form which contains a <textarea> tag. In the browser, I type in the following string:
<a name="test">test</a>
I then hit the submit button, which posts the data to my target file which contains my php code. In my php code, I want to invoke the xml parser to parse the xml I typed in the field. However, nothing happens. I did an echo on the posted data, and which returned the following:
test
I tried the funtion htmlentities($content) and I go the following returned from the echo:
<a name=\"test\">test</a>
however, the parse still doesn't find anything. Is there something I can do to turn the posted data into proper XML that the parser will accept? I know my parser code is working, because I can create a local variable like the following:
$xml = "<a name=\"stuff\">stuff</a>";
and it parses fine. Here is the code I am working with. My text area name is called content, hence the $content used in the script.
<?php
$test = htmlentities($content);
echo "$test<br>";
echo "$content<br>";
$myParser = xml_parser_create();
xml_set_element_handler($myParser,"startTag","endTag");
xml_set_character_data_handler($myParser,"data");
xml_parse($myParser, $test);
function startTag($parser,$tag,$attributes)
{
echo "start";
var_dump($parser,$tag,$attributes);
echo "<br>";
}
function data($parser,$cdata) {
echo "data";
var_dump($parser,$cdata);
echo "<br>";
}
function endTag($parser,$tag) {
echo "end";
var_dump($parser,$tag);
echo "<br>";
}
?>
Here's the source form:
<head><title>test</title></head><body>
<form method="post" action="test.php">
<textarea name="content" row=10 col=10></textarea>
<input type="submit" value="submit"/>
</form></body>
Any help would be appreciated.