我有一個'IMG'具有多個值的 POST 變量,如下例所示:IMG=url.com/img1.png|url.com/img2.png|url.com/img3.png&...因此圖像的三個 URL 由 分隔,|但位于單個POST變量中。正確讀取和處理這些值的最佳方法是什么?我需要將這些值作為單獨的變量或數組來正確處理它們。
3 回答
牛魔王的故事
TA貢獻1830條經驗 獲得超3個贊
您可以簡單地使用explode()您的字符串|作為分隔符:
<?php
$urls = explode("|", $_POST['IMG']);
echo $urls[0]; // url.com/img1.png
echo $url[1]; // url.com/img2.png
echo $url[2]; // url.com/img3.png
慕無忌1623718
TA貢獻1744條經驗 獲得超4個贊
我認為有一種方法是先檢查 POST 變量 IMG 是否存在。然后使用 PHP Explode() 函數分解其內容。
$image_urls = array(); //blank array assuming there are no image URLs
if(isset($_POST['IMG']))
{
$image_urls = explode('|', $_POST['IMG']);
}
//Below code will check if the array actually has image URL parts from
//POST variable IMG
if(count($image_urls) > 0)
{
//your code to process the images
}
- 3 回答
- 0 關注
- 177 瀏覽
添加回答
舉報
0/150
提交
取消
