Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>here's a quick and dirty solution which works:</p> <pre><code>&lt;?php $line = '&lt;polygon id="svg_806" fill-rule="nonzero" fill="black" stroke-linejoin="round" stroke-width="0" points="94.08955764770508,275.3258819580078 99.92155838012695,275.3258819580078 99.92155838012695,281.16587829589844 94.08955764770508,281.16587829589844 "/&gt;'; $xml = simplexml_load_string($line); $ps = explode(" ", $xml-&gt;attributes()-&gt;points); $points = array(); $i = 1; foreach($ps as $point){ $exploded = explode(",", $point); $points["x".$i] = $exploded[0]; $points["y".$i] = $exploded[1]; $i++; } print_r($points); ?&gt; </code></pre> <p>This leads to this output:</p> <pre><code>Array ( [x1] =&gt; 94.08955764770508 [y1] =&gt; 275.3258819580078 [x2] =&gt; 99.92155838012695 [y2] =&gt; 275.3258819580078 [x3] =&gt; 99.92155838012695 [y3] =&gt; 281.16587829589844 [x4] =&gt; 94.08955764770508 [y4] =&gt; 281.16587829589844 [x5] =&gt; [y5] =&gt; ) </code></pre> <p>Now you can access the needed elements of the array with: $points["x1"] $points["y1"] ...</p> <p>Hope this helps</p> <p>To answer the question in your comment, here is the solution:</p> <pre><code>$input = "2957 1620 1124 3836 1524 3836 1524 3684 1924 3684 3324 3838 3724 3838 584 3574"; $i = $count = 1; $points = array(); $exploded = explode(" ", $input); foreach ($exploded as $current){ if($count % 2 == 1){ //X $points["x".$i] = $current; }else{ //y $points["y".$i] = $current; $i++; } $count++; } print_r($points); </code></pre> <p>leads to:</p> <pre><code>Array ( [x1] =&gt; 2957 [y1] =&gt; 1620 [x2] =&gt; 1124 [y2] =&gt; 3836 [x3] =&gt; 1524 [y3] =&gt; 3836 [x4] =&gt; 1524 [y4] =&gt; 3684 [x5] =&gt; 1924 [y5] =&gt; 3684 [x6] =&gt; 3324 [y6] =&gt; 3838 [x7] =&gt; 3724 [y7] =&gt; 3838 [x8] =&gt; 584 [y8] =&gt; 3574 ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload