PHP 中 Chrome 上的 SVG 不显示文本

SVG not displaying text on Chrome in PHP

我的 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>";
?>

您的变量 $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>";

您是否尝试删除 <a xlink:href='index.php'> 及其对应的 </a>

我认为不需要 <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>

带有嵌套 link 的 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>

?>