2010-12-29 2 views
0

배열의 기사에서 모든 단락을 가져 오도록 도와주세요. 단락에는 html이 없습니다. 단락을 통해 단락을 구분하면됩니다. 기사에 여러 줄 바꿈이있을 수 있습니다.regex와 PHP를 사용하여 배열에서 기사의 모든 단락을 얻는 방법은 무엇입니까?

+4

질문 '스택 오버플로 ... –

+0

예제가 있습니까? –

+0

예를 들려 줄 수 있습니까? 단락은 다른 형식으로 구별됩니까? 샘플 데이터가 없으면 도움을주지 않고 추측 할 수 없습니다. –

답변

0

라인을 감지하는 작은 프로그램은 배열의 & 풋 나누기 :

<?php 

$text = 'Lorem Ipsum is simply dummy text of the printing and 




typesetting industry. Lorem Ipsum has been the industrys s 
tandard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it 
to make a type specimen book. It has survived not only five centuries, but also the leap into electronic 
typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset 
sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus 
PageMaker including versions of Lorem Ipsum.'; 
$splitted_para_arr = preg_split("/[\n]+/",$text); 
echo '<pre>'; 
print_r($splitted_para_arr); 
echo '</pre>'; 
?> 
+0

예, 많은 변형이 있습니다. 폭발 할 수 있습니다 ("\ n", $ article); 그러나 여러 줄이 한 번에 끊어지는 경우 (예 : "some text \ n \ n \ n 일부 텍스트") 코드가 두 개 이상의 값을 포함하는 배열을 반환합니다. –

+0

당신은 맞습니다, poelinca. 나는 필요한 변화를 만들었습니다. –

+0

답장을 보내 주셔서 감사합니다 ... 제가 사용한 것은 ... – saikat

0
$article = 'line1 
line2 

line3 



line4 line4 line4 

line10 
'; 
//replace multiple linebreaks 
//(trim it too and add a new line at the beginig of the string) 
$article = "\n" . preg_replace('/\n{2,}/', "\n", trim($article)); 
var_dump($article); 
//match all lines 
preg_match_all('/\n(.*)/', $article, $matches); 
var_dump($matches); 
+0

예. 처음에 ... 감사합니다. – saikat

0

어떤이 약을

확인 ' "나에게 정규식을 적어주세요"많이 있습니다
$para="This is line one! 

This is another line."; 

$x=explode("\n",$para); 
echo "<pre>"; 
print_r($x); 
now use array_filter() for the string length >1 
관련 문제