I
I
Ilya2019-02-03 11:22:59
PHP
Ilya, 2019-02-03 11:22:59

How to parse SVG?

Good afternoon!
I have an SVG sprite (any). I need to use PHP to get an array of icon IDs from a sprite (to use them for display on pages). What is the best tool (or algorithm) to use for these purposes?
While I consider variant SimpleXML.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2019-02-03
@jasper-blondin

I used the following code to solve the problem:

$iconList = array();

$sprite = file_get_contents($spritePath);
$result = preg_match_all("/<symbol[^>]*id=\"([-_a-z0-9]+)\"[^>]*>/i", $sprite, $matches);

if($result > 0) {
  $iconList = $matches[1];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question