Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 一些不在代码中的文本将显示在浏览器上_Php_Button_Printf - Fatal编程技术网

Php 一些不在代码中的文本将显示在浏览器上

Php 一些不在代码中的文本将显示在浏览器上,php,button,printf,Php,Button,Printf,以下是输出: 看到Tweet按钮后的文本了吗?它本来应该在那里的,真烦人,但是。。。是的,就在那里。xD 从googlechrome调试器捕获的scren 它发生在这里的某个地方 echo sprintf('<a id="share" target="_blank" data-count="%d" title="Share on Twitter" href="http://twitter.com/share?text=%s&url=%s" class="btn btn-coun

以下是输出:

看到Tweet按钮后的文本了吗?它本来应该在那里的,真烦人,但是。。。是的,就在那里。xD

googlechrome
调试器捕获的scren

它发生在这里的某个地方

echo sprintf('<a id="share" target="_blank" data-count="%d" title="Share on Twitter" href="http://twitter.com/share?text=%s&url=%s" class="btn btn-counter" rel="nofollow">%s</a>​​​​​', $tweets, $text, $url, $placeholder);
以下是超级完整的代码:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">


#share{
            text-decoration: none;
            color: #fff;
            width: 200px;
            height: 50px;
            background-color: #7fad33;
            border-radius: 3px;
            padding: 10px;
        }

</style>

<script type="text/javascript">
    function popupwindow(url, title, w, h) {
        var sheight = window.innerHeight || document.body.clientHeight;
        var swidth = window.innerWidth || document.body.clientWidth;
        var left = (swidth/2)-(w/2);
        var top = (sheight/2)-(h/2);
        return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
    } 
</script>
</head>
<body>
    <center>
        <a id="share" class="facebook" target="_blank" onclick="return !popupwindow(this.href, 'Facebook', '640', '300')" href="http://www.facebook.com/sharer/sharer.php?u=https://www.youtube.com/watch?v=ZO1klxIbUfA">Share</a>
    <?php 
        function get_tweets($url){
            $api = "http://urls.api.twitter.com/1/urls/count.json?url=";

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            curl_setopt($ch, CURLOPT_URL, $api.$url);
            $result = json_decode(curl_exec($ch));

            return $result->count;
        }

        function tweet($url, $text = '', $placeholder = 'Tweet'){
            $text   = urlencode($text);
            $url    = urlencode($url);
            $tweets = get_tweets($url);
            echo sprintf('<a id="share" target="_blank" data-count="%d" title="Share on Twitter" href="http://twitter.com/share?text=%s&url=%s" class="btn btn-counter" rel="nofollow">%s</a>​​​​​', $tweets, $text, $url, $placeholder);
        }

        tweet('https://www.youtube.com/watch?v=[url]', 'The most beautiful story.');
    ?>
</center>

#分享{
文字装饰:无;
颜色:#fff;
宽度:200px;
高度:50px;
背景色:#7fad33;
边界半径:3px;
填充:10px;
}
函数popupwindow(url、标题、w、h){
var sheight=window.innerHeight | | document.body.clientHeight;
var swidth=window.innerWidth | | document.body.clientWidth;
左变量=(开关数/2)-(w/2);
var top=(高度/2)-(高度/2);
返回窗口。打开(url,标题,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizeable=no,copyhistory=no,宽度='+w+',高度='+h+',顶部='+top+',左='+left);
} 

您的源代码中有一堆看不见的字符。我的第一个猜测是:

        tweet('https://www.youtube.com/watch?v=[url]', 'The most beautiful story.');
    ?>
^^^^-- HERE
但很明显,在代码中很难找到它们,因为当您在编辑器中查看这些字符时,它们可能是不可见的

线索是人物本身。我的猜测是,因为您的HTML中没有
标题,所以您的浏览器正在解释标准拉丁字符集中的字节。在这种情况下,所讨论的字节是

226 (0xE2): â
128 (0x80): €
139 (0x8B): ‹
我猜这不是巧合,在UTF-8编码中,这些字节值将构成一个

我认为,基本上,在你的源代码的某个地方,你已经以某种方式粘贴了一些。因为它们是零宽度空间,所以您无法在编辑器中看到它们(编辑器将设置为将这些UTF-8代码正确显示为零宽度空间,从而使它们不可见)。但是当您将它们呈现为HTML时,因为您使用的是非UTF-8编码(由于没有字符集元)它们显示为这些字节的拉丁字符解释,而不是零宽度空间

正如您在评论中提到的,您可以通过为输出设置正确的UTF-8字符集来“解决”问题,但请记住,仍然有一些字符是您不希望输出的。你现在就是看不见他们。最好的办法是在某种编辑器中搜索源代码,这样可以让您看到这些字符的来源并删除它们


在大多数编辑器中,通过使用左/右箭头键在文档的可疑部分运行光标,您可能能够在普通编辑器中“看到”它们。零宽度空间仍然需要点击箭头键才能移动过去,即使它实际上没有显示在屏幕上。

为什么​​​​​' 背后的?它不是来自那个代码,而是来自你调用
tweet()
后所做的任何事情。它出错的原因是你使用了错误的字符集编码。@Barmar“字符集编码”是什么意思。您认为我应该怎么做?当您在
头中添加这些字符集元头时,会出现哪些字符?(一次仅一个):
226 (0xE2): â
128 (0x80): €
139 (0x8B): ‹