首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php http_build_query错误"0=“

php http_build_query错误"0=“
EN

Stack Overflow用户
提问于 2013-07-26 19:23:19
回答 1查看 577关注 0票数 2

嗨,iam使用这个代码发布url并得到结果,但是它在每个结果之前添加=0

我的代码是

代码语言:javascript
复制
    <!DOCTYPE HTML>
<html>
<body>
<h1>In this demonstration:<br />
>tts is done on server side (i.e by using Google-translate server)<br/>
>then the audio received from Google-translate server is saved on your server (local/production)<br />
>and then that saved audio is played through that saved file on this webpage.</h1>
<h3>
Tested with:
Chrome v21 [Working],
Firefox v14 [Not Working, firefox does not support mp3 audio format playback],
IE v9[Working]
</h3>
<hr />
<form method="POST">
Text to convert : <input name="txt" type="text" /><br />
Filename to save (without the extension) : <input name="filename" type="text" /><br />
Convert text to speech : <input name="submit" type="submit" value="Convert" />
</form>

<?php
if (isset($_POST['txt']) && isset($_POST['filename']))
{
    $text=htmlentities($_POST['txt']);
    $filename=$_POST['filename'].'.mp3';

    $querystring = http_build_query(array($text));

    if ($soundfile = file_get_contents("http://api.voicerss.org?key=c68635f1104b452e8dbe740c0c0330f3&src=$querystring&hl=en-in j"))
    {
        file_put_contents($filename,$soundfile);
        echo ('
            <audio autoplay="autoplay" controls="controls">
            <source src="'.$filename.'" type="audio/mp3" />
            </audio>
            <br />
            Saved mp3 location : '.dirname(__FILE__).'\\'.$filename.'
            <br />
            Saved mp3 uri : <a href="'.$filename.'">'.$_SERVER['SERVER_NAME'].'/webtts/'.$filename.'</a>'
        );
    }
    else echo("<br />Audio could not be saved");
}
?>

其结果是http://api.voicerss.org?key=c68635f1104b452e8dbe740c0c0330f3&src=0=Good+evening.+Please+sit+down.+Now+tell+me+about+your+problem&hl=en-in

它不应该显示src=0=Good,它应该显示src=Good+evening,如何删除0=

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-26 19:28:00

您需要向http_build_query提供一个关联数组

所以改变

代码语言:javascript
复制
 http_build_query(array($text))

代码语言:javascript
复制
 http_build_query(array("src"=>$text))

代码语言:javascript
复制
 file_get_contents("http://api.voicerss.org?key=c68635f1104b452e8dbe740c0c0330f3&src=$querystring&hl=en-in j

代码语言:javascript
复制
file_get_contents("http://api.voicerss.org?key=c68635f1104b452e8dbe740c0c0330f3&$querystring&hl=en-in j

或者,您可以使用

代码语言:javascript
复制
http_build_query(array(
     "src"=>$text,
     "key"=>"c68635f1104b452e8dbe740c0c0330f3",
     "hl"=>"en-in j"))

代码语言:javascript
复制
file_get_contents("http://api.voicerss.org?".$querystring);
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17889358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档