我使用php根据网络中设备的可用性返回SVG图像.
生成的SVG最初包括一个背景色和三行文本.如果我在html页面中使用图像,或者直接在浏览器中打开它,这一切都很好用.
然后我想添加一个基于设备类型的小象形图(也是SVG).
如果我直接调用SVG,则第二个SVG显示 如果我在html中使用svg,第二个svg将不会显示(没有错误图标--什么都没有)--只有文本和背景工作 如果我输入的类型不存在第二个SVG文件,浏览器将显示包含在SVG中的错误图标,如果从html调用,错误图标也会丢失.
我错过了什么/搞砸了什么?提前谢谢!
这是php的相关部分.
<?php
header('Content-Type: image/svg+xml');
$sName = $_GET['name'];
$sIP = $_GET['ip'];
$sCheckFor = $_GET['suche'];
$sType = $_GET['typ'];
#[...] curl and such things
echo '<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="100">
<rect x="0" y="0" width="200" height="100" style="fill: ' . htmlspecialchars( $color, ENT_QUOTES ) . '"/>
<text fill="' . $sTextColor . '" font-size="24" x="50%" y="25" dominant-baseline="middle" text-anchor="middle">' . str_replace("_", " ", $sName) . ' </text>
<text fill="' . $sTextColor . '" font-size="12" x="50%" y="52" dominant-baseline="middle" text-anchor="middle">' . $sIP . ' </text>
<text fill="' . $sTextColor . '" font-size="18" x="50%" y="75" dominant-baseline="middle" text-anchor="middle">' . $response . ' </text>';
echo '<image x="10%" y="32%" width="50px" height="50px" href="./icons/' . $sType . '.svg" />';
echo '</svg>';
这就是html文件:
<img src="./checkDevice.php?name=AmbiLamp&suche=AmbiLamp&ip=192.168.88.88&typ=lmp">