I was recently asked to draw some flags of the world in SVG (Scalable Vector Graphics). One of the flags was the EU flag which has 12 stars arranged like a clock face.
I.E.
Initially I was just going to repeat everything 12 times for the twelve stars and then wondered if PHP would work inside SVC code. I tried it and it works perfectly,
The code,
The above is an image so it preserves the colours. I'll attach the actual file for anyone that wants to play. BTW, you can cut and paste the file into w3schools and have a play.
Hope someone finds this useful.
Mike.
Edit, had to change the file type to .txt, just change it back to .html
Spoke too soon. The above code does work in the php editor/simulator on the w3schools site but not on a real web server. On a real server (actually local host on a WAMP server) it throws two errors, first being "Error: <g> attribute transform: Expected number, "rotate(\u003C?php echo $x;?\u003E…"." which is because it's converting the oppening less than symbol to unicode and breaking it.
Anyone know a way around this?
Mike.
Edit, just tried on a real webserver (https://mikesplaysite.com/EU.html) and it's still broken.
Edit2, realised now that php is server side and would have to echo all the generated svg code.
When I write php pages, I never interleave html and php - I switch to PHP on the first line and it ends at the end of the file, using echo for normal output or heredoc / nowdoc for html blocks.