Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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
SVG文件上的PHP Preg Replace导致分段错误_Php_Regex_Svg_Segmentation Fault_Preg Replace - Fatal编程技术网

SVG文件上的PHP Preg Replace导致分段错误

SVG文件上的PHP Preg Replace导致分段错误,php,regex,svg,segmentation-fault,preg-replace,Php,Regex,Svg,Segmentation Fault,Preg Replace,当我尝试在SVG文件上运行此命令时,浏览器会显示未收到任何数据,并且我的Apache日志文件中出现错误 preg_match("/(<g(\s|\S)*?<\/g>)/i", $SVG, $Matches); preg_match(“/”(使用来解析XML文件 由于您正在查找所有的标记,因此可以这样做: $xdoc = new DOMDocument; // load your .svg $xdoc->Load('0057b8.svg'); // get all "g"

当我尝试在SVG文件上运行此命令时,浏览器会显示未收到任何数据,并且我的Apache日志文件中出现错误

preg_match("/(<g(\s|\S)*?<\/g>)/i", $SVG, $Matches);
preg_match(“/”(使用来解析XML文件

由于您正在查找所有的
标记,因此可以这样做:

$xdoc = new DOMDocument;
// load your .svg
$xdoc->Load('0057b8.svg');
// get all "g"-tags
$gTags = $xdoc->getElementsByTagName('g');
// since the return is a DOMNodeList, we loop through all (even if it's only 1)
foreach($gTags as $gTag) {
    // and here we can e.g. get the attributes
    echo $gTag->getAttribute('transform') . PHP_EOL;
    echo $gTag->getAttribute('fill') . PHP_EOL;
    echo $gTag->getAttribute('stroke') . PHP_EOL;
    // or set a new attribute
    $gTag->setAttribute('stroke-width', '5');
}

g标签将是,因此您可以在参考中阅读,以获得所有可能的方法。

您不能认真对待接近投票吗?我正在使用
preg_replace
函数,并得到一个错误,我不知道如何在接收错误的上下文中解决。以什么可能的方式这不是编程问题?Doe如果你在本地机器上测试它,regex的工作原理是什么?你能提供
$SVG
的内容吗(谷歌要求获得查看它的权限)?尝试在SVG仍然失败时将其剥离到最低限度。SVG是xml,我不知道为什么会出现段错误,但好的方法是使用xml解析器,例如DOMDocument或组合XMLReader/XMLWriter,而不是
preg_replace
Yes!这正是我在寻找的东西,我知道解析xml的困难所在/HTML和正则表达式,但我似乎找不到另一种方法来做它,但这是完美的工作。谢谢!