mattykewl Posted January 28, 2007 Share Posted January 28, 2007 Hi, I was wondering if someone could help me, i don't understand how to format<?php$xmlfile = fopen("squad.xml", "w");[color=red]fwrite($xmlfile,"<?xml version="1.0"?>"); [/color] fclose($xmlfile);?>That line, i understand its the "" that will be causing the problem? or it could be something else like the <>??? how could i format this line in fwrite so it can be writen like that into the file but also php-friendly.Many thanks!!! Link to comment https://forums.phpfreaks.com/topic/36058-formatting-this-line-correctly-in-fwrite-function/ Share on other sites More sharing options...
HuggieBear Posted January 28, 2007 Share Posted January 28, 2007 [code=php:0]<?php$xmlfile = fopen("squad.xml", "w");fwrite($xmlfile,"<?xml version=\"1.0\"?>");fclose($xmlfile);?>[/code]This should work. Backslashes act as escape characters.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/36058-formatting-this-line-correctly-in-fwrite-function/#findComment-171133 Share on other sites More sharing options...
mattykewl Posted January 28, 2007 Author Share Posted January 28, 2007 AHA genius!! thanks so much this has been buggin me for ages!! Link to comment https://forums.phpfreaks.com/topic/36058-formatting-this-line-correctly-in-fwrite-function/#findComment-171134 Share on other sites More sharing options...
HuggieBear Posted January 28, 2007 Share Posted January 28, 2007 No problem, don't forget to mark the topic as 'SOLVED'RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/36058-formatting-this-line-correctly-in-fwrite-function/#findComment-171149 Share on other sites More sharing options...
kenrbnsn Posted January 28, 2007 Share Posted January 28, 2007 Or you could use single quotes to delimit the string, then you don't have to escape the double quotes:[code]<?php$xmlfile = fopen("squad.xml", "w");fwrite($xmlfile,'<?xml version="1.0"?>');fclose($xmlfile);?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/36058-formatting-this-line-correctly-in-fwrite-function/#findComment-171164 Share on other sites More sharing options...
HuggieBear Posted January 28, 2007 Share Posted January 28, 2007 [quote author=kenrbnsn link=topic=124407.msg515420#msg515420 date=1169998350]Or you could use single quotes to delimit the string, then you don't have to escape the double quotes[/quote]Matty,What Ken said is very true, and probably in this situation the better way to go. Having said that, it is important you know how to escape special characters within strings.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/36058-formatting-this-line-correctly-in-fwrite-function/#findComment-171168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.