편집기 사용자가 html을 쉽게 작성할 수 있도록 필터 함수를 작성하려고합니다. 아코디언 블록 텍스트의 다른 조각 사이에 나타납니다일치 항목을 찾고 배열을 채우기
가Fusce eget sapien a tortor hendrerit pharetra sed a libero. Vestibulum quis dui sed elit semper semper non molestie nulla. Curabitur suscipit feugiat varius.
{{accordion}}
{{title}}1 This is the first accordion title{{title_end}}
{{body}}1 This is the first accordion body{{body_end}}
{{title}}1 This is the second accordion title{{title_end}}
{{body}}1 This is the second accordion body{{body_end}}
{{title}}1 This is the third accordion title{{title_end}}
{{body}}1 This is the third accordion body{{body_end}}
{{accordion_end}}
Nulla consequat cursus turpis vitae pretium. Suspendisse iaculis nisl rhoncus justo luctus vel scelerisque diam volutpat.
{{accordion}}
{{title}}2 This is the first accordion title{{title_end}}
{{body}}2 This is the first accordion body{{body_end}}
{{title}}2 This is the second accordion title{{title_end}}
{{body}}2 This is the second accordion body{{body_end}}
{{title}}2 This is the third accordion title{{title_end}}
{{body}}2 This is the third accordion body{{body_end}}
{{accordion_end}}
Ut imperdiet odio quis diam ornare in congue purus rhoncus. Quisque scelerisque est sed sapien facilisis a facilisis turpis adipiscing. In hac habitasse platea dictumst.
주, 그들은 여러 발행 수에 나타납니다
사용자는 다음과 같이 입력 텍스트를 가고있다.
저는 아코디언을 테마로하는 템플릿을 사용하고 있으므로 아코디언을 배열로 구성하고 텍스트의 올바른 위치에 테마 아코디언을 삽입하고 싶습니다.
Array
(
[0] => Array
(
[title] => 1 This is the first accordion title
[body] => 1 This is the first accordion body
)
[1] => Array
(
[title] => 1 This is the second accordion title
[body] => 1 This is the second accordion body
)
[2] => Array
(
[title] => 1 This is the third accordion title
[body] => 1 This is the third accordion body
)
)
나는 preg_replace_callback으로 장난하고있다. 그러나 나는 이것을 할 올바른 방법을 찾지 못한다.
지금까지 필자는 다음과 같이 해왔 :function format_accordion($text) {
$regex = '#{{accordion}}(.+?){{accordion_end}}#is';
return preg_replace_callback(
$regex,
"lolfunction",
$text);
}
function lolfunction($accordion_content) {
$title_regex = '#{{title}}(.+?){{title_end}}#is';
$body_regex = '#{{body}}(.+?){{body_end}}#is';
$data = array();
foreach ($accordion_content as $key => $value) {
$data[$key]['title'] = $key . " title"; // I need to find the titles
$data[$key]['body'] = $key . " body"; // I need to find the bodies
}
return theme("kunsten_accordion", array("data" => $data));
}
주제() 함수는 HTML 템플릿에 배열을 전달합니다. 난 그냥 하나의 기능 format_accordion() : 모든 것을 가지고 기대했던 때문에, 함수 lolfunction를()라는 이름의
그것이 정말 쉽게됩니다 표준 XML (또는 심지어 HTML)을 사용하여 텍스트를 마크 업할 수 있다면'{{accordion}} {{title}} {{body}}'를 작성하십시오. XML (' ')을 사용하면 맞춤 구문 분석기를 작성할 필요가 없습니다. –
나는 그들에게 html을 쓰길 원치 않는다. 그것은 그들이 클래스를 써야한다는 것을 의미한다. 하지만 XML을 작성하게하는 것이 좋습니다. 그러나 여전히 xml 태그를 html + 클래스로 대체해야합니다. 어떤 아이디어? – tolborg
그 반대의 경우는 제외하고. 나는 문자열이 있습니다. 그런 다음 일치 항목을 배열로 바꿉니다. 그런 다음 배열을 새 문자열로 포맷하십시오. 그런 다음 새 문자열을 원본 텍스트에 다시 삽입하십시오. – tolborg