Reputation: 303
how to do this in php. Do i need to use an php library
<svg
xmlns="http://www.w3.org/2000/svg" width="360" height="180">
<circle class="little" cx="180" cy="45" r="12"/>
<circle class="little" cx="60" cy="90" r="12"/>
<circle class="little" cx="300" cy="135" r="12"/>
</svg>
Hi i have an xml data above i just want this to save in my folder: images/circle.svg
Is there anyone here can help me. Thank you very much
Upvotes: 2
Views: 12363
Reputation: 121
Below code working 100%, hope it will help in your project.
<?php
ob_start();
echo '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>';
$content = ob_get_clean();
if(file_put_contents("circle.svg", $content)) { // Filename for storing purpose
echo "Success";
}
else {
echo "Failed to save file";
}
?>
Upvotes: 0
Reputation:
So you've got the data stored as a variable, right? Easy peasy.
file_put_contents('images/circle.svg', $SVGData);
Upvotes: 6