2016-09-19 4 views
1

날짜순으로 정렬 된 이벤트 목록이 있으며 각 이벤트는 <p> 내에 있습니다. 이 더 그 200이며 (나는 이미 조금 그것을 청소 관리) 다음과 같습니다200 개의 문단 목록 순서 반전

<p><strong>1 july 2011</strong> event 1<br> 
Place where the event 1 takes place<br> 
more infos about event 1<br> 
event more infos about event 1</p> 
<p><strong>2 september 2011</strong> event 2<br> 
Place where the event 2 takes place<br> 
more infos about event 2<br> 
event more infos about event 2</p> 
<p><strong>3 september 2011</strong> event 3<br> 
Place where the event 3 takes place<br> 
more infos about event 3<br> 
event more infos about event 3</p> 

그들은 현재 날짜 (가장 오래된 이벤트)으로 분류되어 나는이 할 싶은 것이 가장 새로운 이벤트를 먼저 수행하도록 순서를 바꿉니다.

마커는 각 이벤트가 캡슐화 된 <p>입니다. 날짜는 항상 동일한 형식이 아닙니다.

나는 excel, notepad ++ 및 그의 정규식을 사용하여 작업을 시도했지만 PHP 및/또는 JS와 관련이 있습니까?

여러분이 도와 드릴까요?

감사합니다.

+0

이 다시하기 전에 그들에 기능을 반대로 당신이 배열로 필요로하는 단락을 모두 가져온 다음 배열을 실행 출력 또는 어레이를 거꾸로 통과하여 출력 할 수 있습니다. 이 정보를 사용하면 코드를 조합 할 수 있으며 문제가 발생하면 도움을 줄 수 있습니다. – gabe3886

+0

어떻게 데이터를 페인팅합니까? 이 코드에서는 ordenation 메서드를 매우 간단하게 추가 할 수 있지만 공유하는 코드는 도움이되지 않습니다. 우리는 여기서 실명입니다. –

+0

당신의 답변은 preg_match_all 함수로 explode 메소드에 대해 생각하게했습니다. 나는 그것을 시도 할 것이다. 감사 ! – Cyc

답변

0

가끔은 간단하지만 해결책을 찾기 위해 다른 사람들에게 설명해야합니다. 그래서 거기에 있습니다.

$string = "<p>blablabla</p><p>blablabla 2</p>"; 
$text = str_replace('</p>', '', $string); 
$array = explode('<p>', $text); 
$array = array_reverse($array); 

너무 간단합니다!

2

자바 스크립트에서는 각 단락을 읽고 역순으로 반복 할 수 있습니다. 이게 당신이 한 일 이니?

$(function() { 

    var paras = $('#container p'); 
    var newhtml = ""; 
    for(var i=paras.length-1;i>=0;i--) 
    { 
     newhtml += $(paras[i]).html() + "</br>"; 
    } 
    $('#container').html(newhtml); 
}); 

Example Fiddle

+0

프로그래밍 방식 솔루션 –

0

당신은 REG-특급으로 수행하려는 경우 :

$a = '<p><strong>1 july 2011</strong> event 1<br> 
Place where the event 1 takes place<br> 
more infos about event 1<br> 
event more infos about event 1</p> 
<p><strong>2 september 2011</strong> event 2<br> 
Place where the event 2 takes place<br> 
more infos about event 2<br> 
event more infos about event 2</p> 
<p><strong>3 september 2011</strong> event 3<br> 
Place where the event 3 takes place<br> 
more infos about event 3<br> 
event more infos about event 3</p>'; 

$a = str_replace("\n","", $a); // maybe you dont need this line it happened to me couse of copy-paste from your question text 
preg_match_all("/\<p\>(.*)\<\/p\>/U", $a, $m); 

var_dump(array_reverse($m[1]));