我正在制作一本语音词典。这是我的密码。它运行良好,没有任何错误,只是有一个小问题。终点线是我遇到问题的地方。
http://tts-api.com/tts.mp3?q=$z";?>"type="audio/mp3"/>
$x和$y变量包含一个单词。。因此,它们可以很容易地转换为语音,而无需编码,我的代码对它们来说也很好。但是当我写存储含义的$y时,语音输出不存在,因为含义包含多个单词串,必须首先对其进行编码(但我不知道如何编码)。
请告诉我,为了将意义部分也从文本转换为语音,我必须做哪些更改。
我试过了http://tts-api.com/tts.mp3?q=.urencode($y)";?>"type="audio/mp3"/>
但它不起作用。PLZ帮助
<html>
<head>
<title>Word meanings</title>
<?php
mysql_connect("localhost", "root", "radhika");
mysql_select_db("dictionary");
if(isset($_POST['Submit1']))
{
$req=$_REQUEST['word'];
$strSQL = "SELECT * FROM dict WHERE word='$req'";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs))
{
$x=$row["word"];
$y=$row["meaning"];
$z=$row["synonym"];
echo "<b>Word</b>: " . $x ."<br/>" ;
echo "<b>Meaning</b>: " . $y ."<br/>" ;
echo "<b>Synonym</b>: " . $z ."<br/>" ;
}
}
mysql_close();
?>
</head>
<body>
<form name="form1" action="lastry.php" method="POST">
<input type="text" name="word" value="<?php echo isset($_POST['word'])?$_POST['word']:''?>"x-webkit-speech/>
<Input Type ="Submit" Name ="Submit1" Value ="submit">
</form>
<?php if($_POST)
{
?>
<audio controls="controls" autoplay="autoplay">
<source src="<?php echo "http://tts-api.com/tts.mp3?q=$z";?>" type="audio/mp3" />
</audio>
<?php }?>
</body>
</html>
我建议先尝试URLncode函数,然后告诉我们结果:
例如
urlencode($z)
代替任何可能具有空格/特殊字符的变量。
尝试
http://tts-api.com/tts.mp3?q=<?php echo urlencode($y);?>&type="audio/mp3" />