I have a string:
$s = '<div data-x="0" data-y="0">Some text asdasdas</div>
<div data-x="0" data-y="-1000">Some text...</div>
<div data-x="0" data-y="-2000">Some text foobar</div>
<div data-x="500" data-y="-3000">Some t..</div>';
The string can be different. Divs can include classes and etc.
How to get value from data-x and data-y of each Div?
Like:
$x1 = 0; $y1 = 0;
$x2 = 0; $y2 = -1000;
$x3 = 0; $y3 = -2000;
$x4 = 500; $y4 = -4000;
I would like to explode the string into an array, but then I don’t know what to do ..
Use a proper HTML parser for this:
If you truly want
$x<n>and$y<n>style variables (where<n>represents a number) as a result (in stead of an array of results), then you could replace theforeachloop with something like:I would still recommend collecting them in an array in stead though; makes for much easier processing afterwards.