2015-06-15 36 views
0

所以我試圖在一箇中心php文件中集中產品,並讓我的客戶端PHP只是請求信息,所以我只需編輯中心php文件來添加和刪除產品將php數組的部分提取到客戶端

我的服務器端

$varProduct= (

//  [0]  [1] [2] [3 4 5 6 7]    [8] 
array("Title" , 0001 , 100, 0,0,1,1,0, "/womens/tops/s/2.png", "/womens/tops/s/2.jpg", "/womens/tops/s/2.jpg", 50 ) 

) 

在我的HTML客戶端我要顯示的標題,價格[2]和URL [8] 基本上

for(i=o, i< $varProduct.length(), i++){ 

//display $varProduct[i][0]; 
//display the Image for $varProduct[i][8]; 
//display $varProduct[i][2]; 

} 

我怎麼能在我的客戶端在我的服務器端文件中的值在HTML標籤內?我需要以內聯方式顯示它們,才能夠格式化變量?

回答

1

嘗試這樣的事情

<?php 
for ($i = 0; $i < count($varProduct); $i++) { 
    //full path -- then post pram 
    $return = sendPostData("http://stackoverflow.com/", array('parm1' => $varProduct[$i][0], 'parm2' => $varProduct[$i][0])); 
    print_r($return); 
} 
?> 

<?php 

//send data function 
function sendPostData($url, Array $post) { 
    $data = ""; 
    foreach ($post as $key => $row) { 
     $row = urlencode($row); //fix the url encoding 
     $key = urlencode($key); //fix the url encoding     
     if ($data == "") { 
      $data .="$key=$row"; 
     } else { 
      $data .="&$key=$row"; 
     } 
    } 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    $result = curl_exec($ch); 
    curl_close($ch); // Seems like good practice 
    return $result; 
} 
?> 
+0

我需要用捲曲的話,我會更新的答案等待 –

+0

@RyanWilliams OP「試試這個」?請添加一個解釋,你做了什麼,爲什麼你這樣做,不僅是爲了OP,而且是爲了未來的訪問者。 –

+0

@RyanWilliams現在檢查 –