php 逗號 explode分割字符串 或 implode組裝成字符串


php 逗號 分割字符串 介紹兩個函數給你 <?php //利用 explode 函數分割字符串到數組 
$source = "hello1,hello2,hello3,hello4,hello5";//按逗號分離字符串 
$hello = explode(',',$source); for($index=0;$index<count($hello);$index++){ echo $hello[$index];echo "</br>"; } ?> 
<?php //split函數進行字符分割 // 分隔符可以是斜線,點,或橫線 
$date = "04/30/1973"; list($month, $day, $year) = split ('[/.-]', $date); echo "Month: $month; Day: $day; Year: $year<br />\n"; ?>

 

組裝成字符串:

  checkbox提交過來一個數組,為了將數組中的值插入到SQL語句執行,需要將數組的鍵值使用逗號隔開: index.html
<form action="2.php" method="post"> <input name="select[]" type="checkbox" value="1" />1 <input name="select[]" type="checkbox" value="2" />2 <input name="select[]" type="checkbox" value="3" />3 <input type="submit" value="submie" /> </form>

2.php

<?php $array = $_POST["select"]; $select = implode(",", $array); echo $select; ?>


  3個checkbox全都選擇提交后,輸出的結果為:1,2,3,可以直接插入到SQL語句執行。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM