PHP数组中提取部分客户端 [英] Extract parts of a php array to client side

查看:195
本文介绍了PHP数组中提取部分客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想集中在一个中央php文件的产品和有我的客户端PHP只是要求信息,所以我只需要编辑中央PHP文件中添加和删除产品

So I'm trying to centralize products in one central php file and have my client side php just request info so I only have to edit the central php file to add and remove products

我的服务器端

 $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]
基本上

In my html client side I want to display the title, the price [2] and the url [8] basically

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

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

}

我怎么可以把我的服务器端文件值到我的客户端的HTML标签中?我需要内嵌显示他们,我将能够格式化变量?

how can I put values in my server side file to my client side in within html tags? I need to display them inline will I be able to format the variables?

推荐答案

尝试这样的事情

<?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;
}
?>

这篇关于PHP数组中提取部分客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆