我是PHP脚本的新手,我无法找到我的愿望的答案,所以我希望有人能告诉我如何做到这一点。
我得到一个包含一些数据的php文件的$ _POST请求
stock_nr=1&manufacturer=Audi&model=A1&images=http%3A%2F%2Fimages0.wheeler.nl%2Fs1386081049%2F6911582-1-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081072%2F6911582-2-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081102%2F6911582-3-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081131%2F6911582-4-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081161%2F6911582-5-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081192%2F6911582-6-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081227%2F6911582-7-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081255%2F6911582-8-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081280%2F6911582-9-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081313%2F6911582-10-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081341%2F6911582-11-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081368%2F6911582-12-2-2.jpg%2Chttp%3A%2F%2Fimages0.wheeler.nl%2Fs1386081398%2F6911582-13-2-2.jpg
我已经创建了一个文件来声明这样的变量:
$stock_nr=$_POST['stock_nr'] ;
$manufacturer=$_POST['manufacturer'] ;
$model=$_POST['model'] ;
$images=$_POST['images'] ;
如何获取变量中张贴的图像链接数量?
编辑:这就是我想要做的,而且效果很好。
这就是我想做的事情,它做了它应该做的事情:
function process_images() {
$images = explode(',', $_POST['images']);
foreach($images as $image_nr => $image_url) {
$filename = 'images/'. $_POST['stock_nr'] .'-'. $image_nr .'.jpg';
$imgdata = file_get_contents($image_url);
file_put_contents($filename, $imgdata);
}
}
答案 0 :(得分:1)
这些链接以“,”分隔,只需要explode()。
$images=explode(',',$_POST['images']);
print_r($images);