2016-10-22 92 views
0

這是我的文件數據從文件中讀取並存儲到文本框

Alex-10/9/[email protected]@@@@ 

什麼我想要做的是,店裏的每串通過分隔「 - 」,並將其存儲到HTML文本框:

<input type="text" name="username" value="Alex" 
<input type="text" name="date of birth" value="10/9/2008" /> 

到目前爲止,我已經嘗試過。這個'Alex'和'10/9/2008'應該從上面提到的文件中讀取。我可以設法將不同的字符串存儲到數組中。但我不知道如何將這些值放入不同的文本框。下面是我的PHP代碼,我試圖從一個文件,大步流星值讀入數組

$myfile = fopen("records.txt", "r");///This is my file 
while(!feof($myfile)) { 
    $line=fgets($myfile); 
    $array = explode("-",$line); 
} 
+0

會發生什麼情況?你用'$ array'做任何事情嗎? – chris85

回答

1

$array必須包含這樣的事情:

Array([0]=> Alex, [1]=>10/9/2008,[2]=>male, .......) 

所以,用戶名亞歷克斯被存儲在$array[0]和出生日期10/9/2008存儲在$array[1]

<input type="text" name="username" value="<?php echo $array[0]; ?>" /> 
<input type="text" name="date of birth" value="<?php echo $array[1]; ?>" /> 
+0

我的數組像這樣: Helal10/9/[email protected] @@@@ –

+0

它的工作。謝謝您的幫助。 。 。 –

相關問題