javascript - PHP/JavaScript 中处理带有特殊字符的 URL

标签 javascript php url

我的网址如下所示:

http://www.myServer.net/Posters/CU_Pete 'sChristmas_PP.png

现在是

{
                    'title'         : 'Pete\'s Christmas',
                    'description'   : 'A light-hearted holiday tale that even adults will enjoy. A young boy has the worst Christmas ever and soon realises that he’s doomed to repeat the same day over and over again.',
                    'thumbnail'     : ['http://www.myServer.net/Posters/CU_Pete'sChristmas_PP.png'],
                    'large'         : ['http://www.myServer.net/Posters/CU_Pete'sChristmas_PP.png'],
                    'button_list'   :
                    [
                        { 'title':'Demo', 'url' : 'index.php', 'new_window' : true }
                    ],
                    'tags'          : ['Movies']
                }

所以问题是 Url 包含特殊字符 ('),这显然不允许我的 java 脚本正确。

因此脚本没有按预期执行。

这是我的 javaScrit 数组生成器

$javascript = array();
$count = sizeof($vodAssetArray);
for ($i = 0; $i < $count; $i++)
{
    $pieces = explode("/", $vodAssetArray[$i]->genre);
    $javascript[] = "
                {
                    'title'         : '" . addslashes($vodAssetArray[$i]->title) . "',
                    'description'   : '" . addslashes($vodAssetArray[$i]->description) . "',
                    'thumbnail'     : ['" . ($vodAssetArray[$i]->posterUrl) . "'],
                    'large'         : ['" . ($vodAssetArray[$i]->posterUrl) . "'],
                    'button_list'   :
                    [
                        { 'title':'Demo', 'url' : 'index.php', 'new_window' : true }
                    ],
                    'tags'          : ['" . $pieces[0] . "']
                }";
}

我尝试使用 urlencode、rawurlencode、json_encode,但图像仍然没有下载。

<script type="text/javascript">
    $(function(){
        $("#demo").grid({
            'genre' : 'All',
            'items' :
                [
                    <?php echo implode(',', $javascript); ?>
                ]
        });
    });
</script>  

请帮我解决这个问题。

最佳答案

将 URL 中的所有撇号替换为 %27。

关于javascript - PHP/JavaScript 中处理带有特殊字符的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27634321/

相关文章:

javascript - 使用 javascript/jquery 将我的网页焦点转移到浏览器地址栏

javascript - 我的文档上的 Jquery Block .ready 功能不起作用

javascript - 将 XML 内容提取到 HTML 中

php - 简单的 DOM file_get_html 不返回任何内容

jquery - jQuery AJAX 拉取后更新 URL

url - Tomcat对URL中的中文进行加密,如何取消?

Javascript 正则表达式按以模式开头的行进行分割

php - 我重置了 xampp localhost 的密码,现在我无法访问 phpmyadmin

php - 获取 Feed 提交结果响应 Amazon MWS Api

url - 用于替换部分 URL 的用户脚本