Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SVG and PHP code combined.

Status
Not open for further replies.

Pommie

Well-Known Member
Most Helpful Member
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.
EU.png

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,
EU_code.png

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
 

Attachments

  • EU.txt
    1,006 bytes · Views: 370
Nice work!
 
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.
 
Last edited:
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top