0

我在 PHP 中的提交按钮上实现的操作未执行。一切正常,没有错误,但是当我单击按钮时没有任何反应。Notepad++ 看到该文件lines.php已被修改。

<html>
<head>
    <title>
        Watch your Language
    </title>
</head>
<body>
    <H2 align="center">
        <form method="post">
            <input type="submit" onclick="English()" name="introdu" value="Choose english">
        </form>
        <a href="index.php">Home</a> | <a href="bot.php">Talk to robot</a>
    </h2>
</body>
</html>

 <script type="text/javascript">
function English()
{<?php
         $myFile = "lines.php";
         $fh = fopen($myFile, 'w');

$eng = <<<TEST
<?php
class TextToSpeech {
    public $mp3data;
    function __construct($text="") {
        $text = trim($text);
        if(!empty($text)) {
            $text = urlencode($text);
            $lang_en="http://translate.google.com/translate_tts?tl=en&q=\{$text}";
            $lang_ro="http://translate.google.com/translate_tts?tl=ro&q=\{$text}";
            $lang_fr="http://translate.google.com/translate_tts?tl=fr&q=\{$text}";
            $language=$lang_en;
            $this->mp3data = file_get_contents($language);
        }
    }

    function setText($text) {
        $text = trim($text);
        if(!empty($text)) {
            $text = urlencode($text);
            $en="http://translate.google.com/translate_tts?tl=en&q=\{$text}";
            $ro="http://translate.google.com/translate_tts?tl=ro&q=\{$text}";
            $fr="http://translate.google.com/translate_tts?tl=fr&q=\{$text}";
            $lang=$en;
            $this->mp3data = file_get_contents($lang);
            return  $this->mp3data;
        } else { return false; }
    }

    function saveToFile($filename) {
        $filename = trim($filename);
        if(!empty($filename)) {
            return file_put_contents($filename,$this->mp3data);
        } else { return false; }
    }
}
?>
TEST;
echo $eng;
fwrite($fh, $eng);
fclose($fh); 
?>
alert("File created");
}
</script>
4

3 回答 3

0

此代码使用相同的方法,并且可以完美运行

<html>
<head><title>Umanizator</title>

</head>
<body><H2 align="center">
<form method="post">
Intrebare
 <input type="text" name="intrebare">
Raspuns
 <input type="text" name="raspuns">
<input type="submit" onclick="Confirmare()" name="introdu" value="Exporta">
</form>
<a href="index.php">Home</a> | <a href="bot.php">Discuta cu robotul</a></h2>
</body>
</html>

<?php
// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("robo") or die(mysql_error());

error_reporting(E_ALL & ~E_NOTICE);
$intrebare=$_POST['intrebare'];
$raspuns=$_POST['raspuns'];
$cod1='mysql_query("INSERT INTO dialog  (intrebare, raspuns) VALUES (\'';
$cod2="'  ,  '";
$cod3="') \")  or die(mysql_error());";


$myFile = "lines.txt";
$intrebari = "intrebari.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$op = fopen($intrebari, 'a') or die("can't open file");

$delimiteaza="\n /*---*/  \n";

fwrite($fh, $delimiteaza);
fwrite($fh, $cod1);
fwrite($fh, $intrebare);
fwrite($fh, $cod2);
fwrite($fh, $raspuns);
fwrite($fh, $cod3);
fwrite($op, $intrebare);
fwrite($op, $delimiteaza);

fclose($fh);


?>

 <script type="text/javascript">
function Confirmare()
{
<?php
mysql_query("INSERT INTO dialog  (intrebare, raspuns) VALUES ('".$intrebare."'  ,  '".$raspuns."') ")  or die(mysql_error());
?>
alert("Linia de cod a fost exportata!");
}
</script>
于 2012-12-10T02:58:42.013 回答
0

这基本上只能通过 Ajax 调用获得。这是我在 Stack Overflow 上找到的一个很好的例子:

https://stackoverflow.com/a/7165616/1439793

于 2012-12-10T03:20:51.463 回答
0

问题解决了。我使用以下代码重写了 $eng 文件:

<<<TEST
<?php
class TextToSpeech {
    public \$mp3data;
    function __construct(\$text="") {
        \$text = trim(\$text);
        if(!empty(\$text)) {
           \$text = urlencode(\$text);
            \$lang_en="http://translate.google.com/translate_tts?tl=en&q={\$text}";
            \$lang_ro="http://translate.google.com/translate_tts?tl=ro&q={\$text}";
            \$lang_fr="http://translate.google.com/translate_tts?tl=fr&q={\$text}";
            \$language=\$lang_en;
            \$this->mp3data = file_get_contents(\$language);
        }
    }

    function setText(\$text) {
        \$text = trim(\$text);
        if(!empty(\$text)) {
            \$text = urlencode(\$text);
            \$en="http://translate.google.com/translate_tts?tl=en&q={\$text}";
            \$ro="http://translate.google.com/translate_tts?tl=ro&q={\$text}";
            \$fr="http://translate.google.com/translate_tts?tl=fr&q={\$text}";
            \$lang=\$en;
            \$this->mp3data = file_get_contents(\$lang);
            return  \$this->mp3data;
        } else { return false; }
    }

    function saveToFile(\$filename) {
        \$filename = trim(\$filename);
        if(!empty(\$filename)) {
            return file_put_contents(\$filename,\$this->mp3data);
        } else { return false; }
    }
}
?>
TEST;
于 2012-12-10T03:22:21.133 回答