shamuraq Posted June 5, 2010 Share Posted June 5, 2010 Hi all i've got this thing that got me stumped... <? ob_start(); $output = "header(\"Content-type: image/svg+xml\")"; $output .= "<?xml version=\"1.0\" standalone=\"no\"?>"; $output .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; $output .= "<svg width=\"750\" height=\"710\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">"; $cx = 110; //Coordinate of x-axis @ centre of circle $cy = 110; //Coordinate of y-axis @ centre of circle //$r = rand(100,150); // radius $r = 100; //Melukis segi empat dari data dinamis yg didapati di atas $output .= "<circle class=\"Connect\" cx=\"$cx\" cy=\"$cy\" r=\"$r\">\n"; $output .= "</circle>\n"; $output .= "</svg>\n"; $date = date('dmy'); $kali = 0; $content = ob_get_clean($output); file_put_contents("1".".svg", $content); ?> I get the file 1.svg (meaning file placement is successful) but when i execute the svg file, it is empty... Error in the browser says XML Parsing Error: no element found Location: file:///D:/Apache%20Group/Apache2/htdocs/math/testing/1.svg Line Number 1, Column 1: ^ Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/ Share on other sites More sharing options...
dabaR Posted June 5, 2010 Share Posted June 5, 2010 Well, the things that jump out at me are... <? $output = "header(\"Content-type: image/svg+xml\")"; $output .= "<?xml version=\"1.0\" standalone=\"no\"?>"; $output .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; ?> Try just echoing out $content instead of writing to file. You might be able to find out something that way. Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/#findComment-1068086 Share on other sites More sharing options...
shamuraq Posted June 5, 2010 Author Share Posted June 5, 2010 Well, the things that jump out at me are... <? $output = "header(\"Content-type: image/svg+xml\")"; $output .= "<?xml version=\"1.0\" standalone=\"no\"?>"; $output .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; ?> Try just echoing out $content instead of writing to file. You might be able to find out something that way. I am successful in using echo but i need to write this to file for future development Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/#findComment-1068087 Share on other sites More sharing options...
dabaR Posted June 5, 2010 Share Posted June 5, 2010 So when you echo $contents, you see the right contents? Did you try opening the SVG file with gedit/notepad/$plain_text_editor? Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/#findComment-1068088 Share on other sites More sharing options...
shamuraq Posted June 5, 2010 Author Share Posted June 5, 2010 So when you echo $contents, you see the right contents? Did you try opening the SVG file with gedit/notepad/$plain_text_editor? Yes... its blank i added error notifier and it says: Warning: Wrong parameter count for ob_get_clean() in D:\Apache Group\Apache2\htdocs\....01.php on line 41 I'm suspecting there's a better syntax to "ob_get_clean($output);" Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/#findComment-1068090 Share on other sites More sharing options...
dabaR Posted June 5, 2010 Share Posted June 5, 2010 Oh, I missed that, why are you output buffering, and storing in a variable at the same time. Try removing the ob_start(), and instead of ob_get_clean($output) just have $output Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/#findComment-1068091 Share on other sites More sharing options...
shamuraq Posted June 5, 2010 Author Share Posted June 5, 2010 Bingo... tt's what i was looking fer... Now i'm very close to it just that the svg is not well formed... the error on firefox says: XML Parsing Error: not well-formed Location: file:///D:/Apache%20Group/Apache2/htdocs/...050610144301.svg Line Number 1, Column 7:header("Content-type: image/svg+xml") ------^ Notepad successfully display: header("Content-type: image/svg+xml") <?xml version="1.0" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <svg width="750" height="710" xmlns="http://www.w3.org/2000/svg" version="1.1"> <circle class="Connect" cx="110" cy="110" r="100"> </circle> </svg> Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/#findComment-1068095 Share on other sites More sharing options...
dabaR Posted June 5, 2010 Share Posted June 5, 2010 Cool. You definitely need to drop the header(...) line. This is the structure you need in the file: <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="5cm" height="4cm" version="1.1" xmlns="http://www.w3.org/2000/svg"> <desc>Four separate rectangles </desc> <rect x="0.5cm" y="0.5cm" width="2cm" height="1cm"/> <rect x="0.5cm" y="2cm" width="1cm" height="1.5cm"/> <rect x="3cm" y="0.5cm" width="1.5cm" height="2cm"/> <rect x="3.5cm" y="3cm" width="1cm" height="0.5cm"/> <!-- Show outline of canvas using 'rect' element --> <rect x=".01cm" y=".01cm" width="4.98cm" height="3.98cm" fill="none" stroke="blue" stroke-width=".02cm" /> </svg> See more here: http://www.w3.org/TR/SVG11/struct.html Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/#findComment-1068096 Share on other sites More sharing options...
ignace Posted June 5, 2010 Share Posted June 5, 2010 You definitely need to drop the header(...) line. That took long for you to notice I was already worried I had to reply that they had to drop $output = "header(\"Content-type: image/svg+xml\")"; for it to work Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/#findComment-1068124 Share on other sites More sharing options...
dabaR Posted June 5, 2010 Share Posted June 5, 2010 What? I mentioned all the problems with the SVG output in my first post. Quote Link to comment https://forums.phpfreaks.com/topic/203937-php-svg-generator/#findComment-1068196 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.