2011-09-10 6 views
1

나는 다음과 같은 코드가 있습니다preg_replace이다

{bookielink href="bet-at-home"} body content{/bookielink} 

을하고 난 다음 싶어 :

<a href="index.php?bookie=bet-at-home">body content</a> 

이 내 시도입니다 :

$buffer = preg_replace("/.*{bookielink[^>]*}|.*/si", "<a>", $buffer); 
$buffer = preg_replace("/.*{\/bookielink}|.*/si", "</a>", $buffer); 
+0

가능한 중복 http://stackoverflow.com/questions/3577641/best-methods-to-parse-html-with-php) – ajreal

+2

@ajreal : 전혀 아닙니다. Kicsi는 사용자 정의 형식에서 HTML을 _ 생성하려고합니다. – Mat

+0

죄송합니다. 아래쪽 투표가 삭제되었습니다. – ajreal

답변

1

다음 :

$buffer = 'foo {bookielink href="bet-at-home"} body content{/bookielink} bar'; 
echo preg_replace(
    '#{bookielink\s+href="([^"]*)"\s*}([^{]+){/bookielink}#i', 
    '<a href="index.php?bookie=$1">$2</a>', 
    $buffer 
); 

인쇄됩니다 :

foo <a href="index.php?bookie=bet-at-home"> body content</a> bar 
([PHP와 HTML을 구문 분석하는 가장 좋은 방법]의
+0

정규식은 제게는 매우 간단합니다. 그러나 설명이 필요하면 그냥 말하면 조금 확장됩니다. –

+0

도움 주셔서 감사합니다. –

관련 문제