我在php中有这个变量:
image/svg+xml,<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="62" height="57"><path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 13 5 c -0.02 0.1 -0.39 4.17 -1 6 c -0.67 2.02 -2.57 3.96 -3 6 c -1.15 5.51 -0.64 12.54 -2 18 c -0.84 3.37 -3.95 6.69 -5 10 c -0.85 2.68 -1 9 -1 9"/><path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 9 29 c 0.09 0 3.62 0.34 5 0 c 1 -0.25 1.99 -1.84 3 -2 c 2.81 -0.43 10 0 10 0"/><path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 29 5 c 0.07 0.21 3.63 8.04 4 12 c 0.9 9.7 0.52 22.2 0 31 c -0.06 1.02 -2 3 -2 3"/><path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 59 1 c 0 0.82 -0.53 33.64 0 47 c 0.04 1.02 1.75 2 2 3 c 0.34 1.38 0 5 0 5"/></svg>
我需要剥离标签SVG以获取此字符串:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="62" height="57"><path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 13 5 c -0.02 0.1 -0.39 4.17 -1 6 c -0.67 2.02 -2.57 3.96 -3 6 c -1.15 5.51 -0.64 12.54 -2 18 c -0.84 3.37 -3.95 6.69 -5 10 c -0.85 2.68 -1 9 -1 9"/><path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 9 29 c 0.09 0 3.62 0.34 5 0 c 1 -0.25 1.99 -1.84 3 -2 c 2.81 -0.43 10 0 10 0"/><path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 29 5 c 0.07 0.21 3.63 8.04 4 12 c 0.9 9.7 0.52 22.2 0 31 c -0.06 1.02 -2 3 -2 3"/><path fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M 59 1 c 0 0.82 -0.53 33.64 0 47 c 0.04 1.02 1.75 2 2 3 c 0.34 1.38 0 5 0 5"/></svg>
但使用strip_tags($string, '<svg>');
我明白了(但这并不好):
image/svg+xml,< svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="379" height="64"></svg>
答案 0 :(得分:0)
您可以使用正则表达式提取svg
元素:
preg_match('/(<svg.+<\/svg>)/im', $string, $match);
echo $match[0];
答案 1 :(得分:0)
您可以使用preg_replace功能删除不需要的文本部分,如下所示:
public class Category {
private String Name;
private String Image;
public Category(){
}
public Category(String name, String image){
Name = name;
Image = image;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getImage() {
return Image;
}
public void setImage(String image) {
Image = image;
}
}
访问this link以查看正在运行的脚本。