我有一个二维数组,我想保存到文件中。文件中的每一行都应该是由选项卡分隔的项目的详细信息。我会告诉你我在几个人的意思。无论如何,我有一个函数将数组拆分成一个字符串并保存到一个文件,但它并没有真正起作用。它给了我一个字符串转换错误的数组。好的,所以这是我的阵列:
{
[0]=> array(8) {
["title"]=> string(20) "The Boys in the Boat"
["author"]=> string(18) "Daniel James Brown"
["isbn"]=> string(10) "067002581X"
["hardcover"]=> string(5) "19.99"
["hc-quantity"]=> int(2)
["softcover"]=> string(5) "16.99"
["sc-quantity"]=> string(1) "9"
["e-book"]=> string(6) "16.99 "
}
[1]=> array(8) {
["title"]=> string(33) "Harry Potter and the Cursed Child"
["author"]=> string(40) "J. K. Rowling, Jack Thorne, John Tiffany"
["isbn"]=> string(10) "1338099133"
["hardcover"]=> string(5) "18.95"
["hc-quantity"]=> string(2) "25"
["softcover"]=> string(5) "17.98"
["sc-quantity"]=> string(1) "0"
["e-book"]=> string(6) "17.98 "
}
[2]=> array(8) {
["title"]=> string(10) "Just Mercy"
["author"]=> string(15) "Bryan Stevenson"
["isbn"]=> string(10) "0812994520"
["hardcover"]=> string(5) "17.50"
["hc-quantity"]=> string(1) "8"
["softcover"]=> string(5) "16.25"
["sc-quantity"]=> string(2) "10"
["e-book"]=> string(6) "16.25 "
}
[3]=> array(8) {
["title"]=> string(13) "Me Before You"
["author"]=> string(10) "Jojo Moyes"
["isbn"]=> string(10) "0670026603"
["hardcover"]=> string(5) "18.95"
["hc-quantity"]=> string(1) "2"
["softcover"]=> string(5) "17.50"
["sc-quantity"]=> string(1) "1"
["e-book"]=> string(6) "17.25 "
}
[4]=> array(8) {
["title"]=> string(24) "A Thousand Splendid Suns"
["author"]=> string(15) "Khaled Hosseini"
["isbn"]=> string(10) "1594489505"
["hardcover"]=> string(5) "19.00"
["hc-quantity"]=> string(1) "7"
["softcover"]=> string(5) "15.50"
["sc-quantity"]=> string(1) "4"
["e-book"]=> string(6) "14.95 "
}
[5]=> &array(8) {
["title"]=> string(19) "The Wright Brothers"
["author"]=> string(16) "David McCullough"
["isbn"]=> string(10) "1476728742"
["hardcover"]=> string(5) "21.95"
["hc-quantity"]=> string(1) "3"
["softcover"]=> string(5) "18.95"
["sc-quantity"]=> string(1) "3"
["e-book"]=> string(6) "18.95 "
}
}
这是我的功能:
function saveorder($file,$arr){
@ $fp = fopen($file, 'w');
flock($fp, LOCK_EX);
$string = '';
foreach($arr as $key => $result)
$string .= "$key: $result \n";
if (!$fp) {
echo "<p>Your order could not be processed at this time.</p>";
}else{
fwrite($fp, $string);
flock($fp, LOCK_UN);
fclose($fp);
echo("<p>Order written to $file file.</p>");
}
}
如果它正在工作,例如,第一行将会读到这样的内容:“船上的男孩\ t撰稿人\精装本”,就像那样。你能帮忙吗?
答案 0 :(得分:1)
Set Con = CreateObject("ADODB.Connection")
Con.ConnectionString = "Provider=SQLOLEDB;Data Source=YOONGTAT\SQLEXPRESS;Database=testing;User ID=sa;password=1234"
Con.open
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open "Select * from dbo.exampletable where user_name like '%" & Request.Form("employeeName[]")(i) & "%' and user_id like '%" & Request.Form("employeeId[]")(i) & "%'" , con