admin管理员组

文章数量:1331674

how to do this in php. Do i need to use an php library

<svg
   xmlns="" 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

how to do this in php. Do i need to use an php library

<svg
   xmlns="http://www.w3/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

Share Improve this question edited Jul 24, 2015 at 8:31 knives22 asked Jul 24, 2015 at 8:25 knives22knives22 3031 gold badge2 silver badges14 bronze badges 10
  • 1 What do you mean, "i have an svg above"? Is it a file? Do you have it rendered on a client? Is it on a printout in your purse? – Amadan Commented Jul 24, 2015 at 8:28
  • im sorry i mean xml data to save as circle.svg file – knives22 Commented Jul 24, 2015 at 8:31
  • Of course; SVG is always XML. The point is, where do you have it? – Amadan Commented Jul 24, 2015 at 8:32
  • i just want to save it as circle.svg in my folder – knives22 Commented Jul 24, 2015 at 8:33
  • 1 I don't know how to ask this any clearer. For the third time, I know that you want to save it, but where is it before that? (I feel like the security guard in Freddy Got Fingered.) – Amadan Commented Jul 24, 2015 at 8:35
 |  Show 5 more ments

2 Answers 2

Reset to default 6

So you've got the data stored as a variable, right? Easy peasy.

file_put_contents('images/circle.svg', $SVGData);

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/2000/svg" xmlns:xlink="http://www.w3/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";
}
?>

本文标签: javascripthow to save an svg file in phpStack Overflow