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!!! Quote 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 Quote 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!! Quote 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 Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.