2011-08-12 6 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