【问题标题】:SVG not displaying text on Chrome in PHPSVG 未在 PHP 中的 Chrome 上显示文本
【发布时间】:2017-07-07 12:59:32
【问题描述】:

我的 PHP 代码通过 SVG 显示文本。当我使用 IE 和 Firefox 时,一切都很好,但在 Chromium 上,我只是得到一张没有文字的图片。

<?php
    echo "<svg width='1100' height='1620'>";
    $text = "Some text to be shown";

    echo "<text x=473  y=81 font-family='Verdana' font-size='18' fill='black'>
                  <a xlink:href='index.php'>
                  <a href='index.php'>$text</a></a>
            </text>";

echo "</svg>";
?>

【问题讨论】:

  • 不是向我们展示 PHP 端,而是向我们展示浏览器接收到的输出。这不是真正的 PHP 问题。看起来这可能是一个有趣的浏览器问题。

标签: google-chrome svg cross-browser


【解决方案1】:

您是否尝试过删除 &lt;a xlink:href='index.php'&gt; 并且它对应的 &lt;/a&gt;

【讨论】:

  • 就是这样。现在一切正常。谢谢
【解决方案2】:

您的变量 $text 需要连接吗?

echo "<text x=473  y=81 font-family='Verdana' font-size='18' fill='black'>
              <a xlink:href='index.php'>
              <a href='index.php'>" . $text . "</a></a>
        </text>";

【讨论】:

  • 我按照你说的做了,但是结果是一样的。在 IE 和 Firefox 上一切正常,但在 Chromium 上仍然没有。
  • 您在开发者控制台中遇到了什么样的错误? @user1043939
【解决方案3】:

我认为不需要&lt;a xlink:href。试试这个。

https://jsfiddle.net/tsekgemo/

<div id="parent">
    <svg width='1100' height='1620'>
        <text x=473 y=81 font-family='Verdana' font-size='18' fill='black'>
            <a href='index.php'>Some text to be shown</a>
        </text>
    </svg>
</div>

【讨论】:

    【解决方案4】:

    带有嵌套链接的 SVG 文本在 chrome 浏览器中不起作用,这就是您的代码假设的样子:

    <?php
    echo "<svg>
       $text = "Some text to be shown";
    
        echo "<text x=473  y=81 font-family='Verdana' font-size='18' fill='black'>
                       <a xlink:href='index.php'></a>
                        <a href='index.php'>$text</a>
                  </text>";
    echo </svg>
    

    ?>

    【讨论】:

      猜你喜欢
      • 2014-11-25
      • 2019-06-02
      • 2013-10-02
      • 2012-06-27
      • 2014-08-30
      • 1970-01-01
      • 2021-10-11
      • 2021-03-26
      • 1970-01-01
      相关资源
      最近更新 更多