2011-08-12 24 views
0
$string = '1.this is the first2.second3.and thethird'; 
$string = str_replace('??', '<br> ??', $string); 
echo $string; 
//output: 
1.this is the first <br> 
2.second <br> 
3.and thethird 

何str_replaceが必要ですか? 出力のフリーリスト番号には<br>タグがありません。 おかげ文字列置換の問題

+0

[preg_replace](http://us.php.net/manual/en/function.preg-replace.php)が必要です。 – webbiedave

答えて

2
$ cat scratch.php 
<?php 
$string = '1.this is the first2.second3.and thethird'; 
$string = preg_replace('/([^0-9])([0-9]+\.)/', "\$1 <br>\n\$2", $string); 
echo $string; 



$ php scratch.php | more 
1.this is the first <br> 
2.second <br> 
3.and thethird 



$ 
-1

私はあなたが入力文字列の上に持っているどのくらいのコントロールを知っているが、(爆発使用していない)は、多くの方が簡単かつきれいです。唯一の要件は、区切り文字を文字列に入れることができる必要があることです。

$string = '1.this is the first|2.second|3.and thethird'; 
$array=explode('|',$string); 
foreach($line as $array){ 
    echo $line."<br>"; 
} 
+0

このソリューションで何が問題になっていますか?それは非常に簡単で効果的です – Landon