2011-09-02 57 views
0

我的一個變量在我的PHP腳本生成一個字符串,如:需要幫助的分裂變量的字符串,並給它分配的部分數組

'something/test/1' 

我想通過關鍵字拆分那種琴絃的/和然後使用preg_match或其他名稱將這些部分分配給PHP中的數組。
輸出應該是這樣的:

array(
    '0' => 'something', 
    '1' => 'test, 
    '2' => '1' 
); 
+3

PHP的文檔非常好,你會很容易地發現了這樣的功能,在看「字符串函數」頁http://php.net/manual/en/ref.strings.php –

回答

2

explode()

<?php 
$te="something/test/1"; 
$ka=explode('/',$te); 
print_r($ka); 
4
$array = explode('/', $string); 
4

有一個叫explode,你想要做什麼PHP函數。 manual here

4

只需使用$array=explode('/',$string)explode函數進行分割並返回所需的數組。