简体   繁体   English

将HTML Texarea内容发送到XML文件

[英]Send HTML Texarea content to XML File

I'm wanting to use an XML file to show some messages in a flash application. 我想使用XML文件在Flash应用程序中显示一些消息。 I'm wanting to populate this XML file using a simple HTML form with a textarea and when a user submits the content it will post it to the XML file. 我想使用带有文本区域的简单HTML表单填充此XML文件,当用户提交内容时,它将把它发布到XML文件中。

The XML file looks like this: XML文件如下所示:

<messages> <msg>This is a sample message</msg> </messages>

I'm presuming this require something like PHP, but if possible would rather use something like jQuery as I would prefer to run it on a local machine instead of on a web server. 我以为这需要PHP之类的东西,但如果可能的话,宁愿使用jQuery之类的东西,因为我希望在本地计算机而不是Web服务器上运行它。

Here is the HTML form: 这是HTML表单:

<form id="myForm">

            <fieldset>

                <textarea id="textArea" placeholder="e.g. When did you last give money to charity?"></textarea>

                <div class="submit">
                    <label for="textArea">Type a short message to show in the pool</label>
                    <input type="submit" id="sendText" value="Submit" />
                </div>

            </fieldset>

        </form>

Thanks. 谢谢。

EDIT: After being told it's not possible with jQuery, I would like to use PHP. 编辑:在被告知无法使用jQuery后,我想使用PHP。 So I'm looking for a simple bit of PHP that will save this as XML. 因此,我正在寻找将其另存为XML的简单PHP。

I'm not sure about the textarea 我不确定文本区域

var message=$("<messages><msg></msg></messages>");
message.find("msg").text=$("#textArea").text();

Unfortunately it is not possible. 不幸的是,这是不可能的。 Javascript, and subsequently jQuery cannot write to files (with limited nonrelated exceptions). Javascript,以及随后的jQuery无法写入文件(具有有限的无关异常)。 However, you mentioned not wanting to use php because you wanted to run it locally on your machine. 但是,您提到不想使用php,因为您想在计算机上本地运行它。 Even through php is a web language and frequently run on servers, you can run php locally without access to a server by turning your own machine into a server. 即使通过php是一种网络语言并且经常在服务器上运行,也可以通过将自己的计算机变成服务器来在本地运行php,而无需访问服务器。 You can get preconfigured and packaged environments that let you run php on your local machine in minutes such as XAMPP: 您可以获得预配置和打包的环境,这些环境使您可以在几分钟内在本地计算机上运行php,例如XAMPP:

http://www.apachefriends.org/en/xampp.html http://www.apachefriends.org/en/xampp.html

<?php

$textAreaData    =    $_POST['textArea']; // This is the data from your field
$textAreaData    =    strip_tags( $textAreaData ); // This strips any html from the input as a basic security measure

$xml    =     <<<XML

<messages>
    <msg>
    {$textAreaData}
    </msg>
</message>

XML;

if ( ! $handle = fopen( 'file.xml', 'a' ) )
{
    die("Unable to open file");
}

if( ! fwrite( $handle, $xml ) )
{
    die("Unable to write to file.");
}

echo "Successfully wrote to xml.";

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM