使用帶尖括號和引號的fwrite

[英]Using fwrite with angle brackets and quotation marks


I'm creating a form to append data into an XML database, which is being read by a widget on another page. The format that I need the data to be in is as follows:

我正在創建一個表單來將數據附加到XML數據庫中,該數據庫由另一個頁面上的小部件讀取。我需要數據的格式如下:

<event start="1914" end="1918" isDuration="true" title="World War I" color="red">
Lots of guns and death.
</event>

However, I'm not sure how to do this with PHP's fwrite function because of the use of angle brackets and quotation marks. For example, I tried the following:

但是,由於使用尖括號和引號,我不知道如何使用PHP的fwrite函數執行此操作。例如,我嘗試了以下內容:

fwrite($database, <event start="$startdate" end="$enddate" 
isDuration="$isDuration" title="$title" color="$color">
$description
</event>);

But this does not work, I get errors about unexpected angle brackets, etc. If anyone can help I would greatly appreciate it.

但這不起作用,我得到意外的尖括號等錯誤。如果有人可以幫助我會非常感激。

2 个解决方案

#1


1  

You're supposed to give it a string.

你應該給它一個字符串。

string

The string that is to be written.

要寫入的字符串。

#2


0  

fwrite($database, "<event start=\"{$startdate}\" end=\"{$enddate}\"  isDuration=\"{$isDuration}\" title=\"{$title}\" color=\"{$color}\"> {$description} </event>"); 

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/03/05/d75fbe011e076970992683d6d566929d.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com