我想用PHP做些事情。如何使用PHP製作關鍵字列表的列表
我有名稱的列表:
first
second
third
forth
現在我想有這樣的:
first,second,third,forth
怎麼能這樣呢一點點的PHP代碼?
我想用PHP做些事情。如何使用PHP製作關鍵字列表的列表
我有名稱的列表:
first
second
third
forth
現在我想有這樣的:
first,second,third,forth
怎麼能這樣呢一點點的PHP代碼?
假設你有這些數組
$arr=array('first','second');
$str=implode(",",$arr);
EDIT(假設每個名字都上新的生產線,我將取代\ n,其中,)
$str=file_get_contents("filename.txt");
$newstr=str_replace("\n",',',$str);
$newstr=trim($newstr, ",");//to remove the last comma
echo $newstr;
這真是基本的PHP,我不敢相信它在大多數教程中都沒有涉及。
$array = file("filename", FILE_IGNORE_NEW_LINES);
$string = implode(',', $array);
我認爲你正在尋找爆炸,像這樣http://us2.php.net/explode
array explode (string $delimiter , string $string [, int $limit ])
你要設置$delimiter
到' '
,$string
可以複製 - >您的text.txt的內容粘貼。
做將是最好的事情:採取的text.txt內容和使用搜索替換刪除新線和添加空格(或逗號),讓你從
ron
john
kahn
去ron, john, kahn
,在這點你可以導入一個數組在php中使用。
你在尋找'implode'嗎? – Barmar
你的意思是?請在提問前提出您的問題 –
,谷歌首先http://www.w3schools.com/php/showphp.asp?filename=demo_func_string_implode –