Get some of the contents of the SVG ID with PHP

0

I have a file SVG and it has several paths with the tag and inside the tag has the id attribute that in turn has the name of the state and also the municipality (which is what I need to get). I would like to get this municipality with the PHP , making a script to go reading the file and pick up within each attribute ID only the municipality. The SVG content looks like this:

<g id="x5F_Bahia_x5F_Nova_Viçosa">
    <path fill-rule="evenodd" clip-rule="evenodd" fill="#B3B3B3" stroke="#FFFFFF" stroke-width="0.2835" stroke-miterlimit="10" d="
        M430.19,291.31l-0.01,0.21l-0.67,0.36l-0.42-0.06l0.17-0.4l0.33-0.01l0.29,0.08L430.19,291.31L430.19,291.31z M424.84,290.44
        l0.68,0.34l0.33-0.17l0.5,0.11l0.45,0.25l0.17-0.09l0.15,0.01l0.32,0.25l0.57,0.09l0.13,0.18l1.03-0.01l-0.15,0.27l0.04,0.31
        l-0.43,0.15l-0.44,0.26l-0.7,0.71l-0.19-0.15l-0.56-0.06l-0.4,0.12l-0.22-0.04l-0.41,0.17l-0.81-0.03l-0.38-0.11l-3.18,0.03
        L421,292.8l0.03-0.17l-0.39-0.05l-0.06-1.23l0.31,0.01l0.45-0.2l0.14-0.05l0.22,0.02l0.37,0.19l0.22-0.06l0.3,0.02l0.04,0.04
        l0.11,0.03l0.17-0.07l0.24-0.22l0.11-0.02l0.25,0.05l0.34-0.15l0.23-0.07l0.03-0.11l0.45-0.26l0.2,0L424.84,290.44L424.84,290.44z"
        />
    <path fill="#B3B3B3" stroke="#FFFFFF" stroke-width="0.2835" stroke-miterlimit="8" d="M430.19,291.31l-0.01,0.21l-0.67,0.36
        l-0.42-0.06l0.17-0.4l0.33-0.01l0.29,0.08L430.19,291.31L430.19,291.31z M424.84,290.44l0.68,0.34l0.33-0.17l0.5,0.11l0.45,0.25
        l0.17-0.09l0.15,0.01l0.32,0.25l0.57,0.09l0.13,0.18l1.03-0.01l-0.15,0.27l0.04,0.31l-0.43,0.15l-0.44,0.26l-0.7,0.71l-0.19-0.15
        l-0.56-0.06l-0.4,0.12l-0.22-0.04l-0.41,0.17l-0.81-0.03l-0.38-0.11l-3.18,0.03L421,292.8l0.03-0.17l-0.39-0.05l-0.06-1.23
        l0.31,0.01l0.45-0.2l0.14-0.05l0.22,0.02l0.37,0.19l0.22-0.06l0.3,0.02l0.04,0.04l0.11,0.03l0.17-0.07l0.24-0.22l0.11-0.02
        l0.25,0.05l0.34-0.15l0.23-0.07l0.03-0.11l0.45-0.26l0.2,0L424.84,290.44L424.84,290.44z"/>
</g>
<g id="x5F_Bahia_x5F_Novo_Horizonte">

As you can see, you have x5F_Bahia_x5F_Nova_Viçosa and x5F_Bahia_x5F_Novo_Horizonte . What I need to get is New_Viçosa and Novo_Horizonte . How can I do this using PHP?

    
asked by anonymous 06.08.2016 / 17:34

1 answer

2

If it is always the same pattern (if the id always has ' x5F ' for ex) even excuse me from using regex, you can with php do:

$id = 'x5F_Bahia_x5F_Nova_Viçosa';
$exp = explode('_x5F_', $id);
$zona = end($exp);
echo $zona; // Nova_Viçosa

With regex it looks like this:

$id = 'x5F_Bahia_x5F_Novo_Horizonte';
$hey = preg_match('/_x5F_(.*)$/', $id, $matches);
echo $matches[1]; // Novo_Horizonte
    
06.08.2016 / 18:07