PECL BBCode 확장자를위한 [YouTube] -Tag를 만드는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/1205492

  •  05-07-2019
  •  | 
  •  

문제

나는 그것을 사용한다 PECL BBCODE 확장 bbcode-tags를 구문 분석합니다.

누구든지 나에게 방법을 보여줄 수 있습니까? 교체 대신 BBCode 태그 사이의 텍스트 주변 HTML 태그와 함께? 나는 만들고 싶다 [youtube] 꼬리표:

[youtube]w0ffwDYo00Q[/youtube]

이 태그에 대한 내 구성은 다음과 같습니다.

$tags = array(
    'youtube' => array(
        'type'     => BBCODE_TYPE_NOARG,
        'open_tag' => 
            '<object width="425" height="350">
                 <param name="movie" value="http://www.youtube.com/v/{CONTENT}"></param>
                 <embed src="http://www.youtube.com/v/{CONTENT}" type="application/x-shockwave-flash" width="425" height="350"></embed>
             </object>',
        'close_tag' => '',
    ),
);

문제 : [youtube] 태그 (YouTube ID)가 두 번 필요합니다 (객체 및 임베드 태그의 경우). close_tag 의도 한대로.

결과 : YouTube 플레이어를 포함시키기위한 마크 업은 올바르게 생성되지만 YouTube-ID가 인쇄됩니다.

<object width="425" height="350">
    <param name="movie" value="http://www.youtube.com/v/w0ffwDYo00Q"></param>
    <embed src="http://www.youtube.com/v/w0ffwDYo00Q" type="application/x-shockwave-flash" width="425" height="350"></embed>
</object>w0ffwDYo00Q

이 문제를 해결하는 방법을 아는 사람이 있습니까?

미리 감사드립니다!

도움이 되었습니까?

해결책

지금 당장 테스트 할 수 없으므로 작동하는지 확실하지 않지만 아마도 이것을 시도 할 수 있습니다.

문서 bbcode_create 태그를 구성하는 데 사용할 수있는 키/값을 설명합니다.
이 키 중 하나는 다음과 같습니다.

content_handling 선택 사항 - 제공합니다 콘텐츠 수정에 사용되는 콜백. 0.10.1 이후에만 지원되는 객체 지향 표기법 콜백 프로토 타입은 문자열 이름 (문자열 $ content, String $ argument)입니다.

그렇다면 해당 속성을 정의하여 컨텐츠를 수정하는 함수에 대한 링크가되면 공허한 문자열로 설정하여 수정하십시오.

이런 것, 아마도 : 아마도 :

$tags = array(
    'youtube' => array(
        'type'     => BBCODE_TYPE_NOARG,
        'open_tag' => 
            '<object width="425" height="350">
                 <param name="movie" value="http://www.youtube.com/v/{CONTENT}"></param>
                 <embed src="http://www.youtube.com/v/{CONTENT}" type="application/x-shockwave-flash" width="425" height="350"></embed>
             </object>',
        'close_tag' => '',
        'content_handling' => 'remove_handler',
    ),
);

그리고 선언 remove_handler 이런 식으로 기능 :

function remove_handler($content, $argument) {
  return '';
}

또는 아마도 그런 식으로 :

function remove_handler(& $content, $argument) {
  $content = '';
}

운이 좋으면 콘텐츠를 제거하기에 충분할 수 있습니까?


내 이전 제안에 대한 의견을 마친 후 편집


안녕하세요,

이번에는 내가 제안한 것을 시도했는데 작동하는 것 같습니다. ;-)

먼저 설정할 수 있습니다 '' 모두 open_tag 그리고 close_tag ; 그런 식으로, content_handling 콜백은 모든 작업에 책임이 있습니다.
이와 같은 것 : :

$tags = array(
    'youtube' => array(
        'type'     => BBCODE_TYPE_NOARG,
        'open_tag' => '',
        'close_tag' => '',
        'content_handling' => 'generate_youtube_tag',
    ),
);

콜백 함수는 다음과 같습니다.

function generate_youtube_tag($content, $argument) {
    // TODO some security checks on $content !
    // Here, I've assumed that a youtube id only contains letters and numbers
    // But I don't know it that's always the case
    if (preg_match('/^[\d\w]+$/', $content)) {
        return <<<NEW_CONTENT
<object width="425" height="350">
    <param name="movie" value="http://www.youtube.com/v/{$content}"></param>
    <embed src="http://www.youtube.com/v/{$content}" type="application/x-shockwave-flash" width="425" height="350"></embed>
</object>
NEW_CONTENT;
    }
    else {
        return '';
    }
}

실제로 전체를 생성합니다 <object> YouTube ID의 두 발생을 포함하여 태그.

그리고 당신이 다음과 같이 부르면 :

$text = '[youtube]w0ffwDYo00Q[/youtube]';
$bbHandler = bbcode_create($tags);
$output = bbcode_parse($bbHandler, $text);
var_dump($output);

이 출력을 얻습니다.

string '<object width="425" height="350">
    <param name="movie" value="http://www.youtube.com/v/w0ffwDYo00Q"></param>
    <embed src="http://www.youtube.com/v/w0ffwDYo00Q" type="application/x-shockwave-flash" width="425" height="350"></embed>
</object>' (length=246)

어떤 것도 괜찮을 것 같아요 ;-)
실제로, 당신이 그것을 ouput한다면 :

echo $output;

비디오가로드되었습니다. ~라고 불린다 사이먼의 고양이 '고양이 남자', btw ;-)


이번에는 이것이 당신의 문제를 더 잘 해결하기를 바랍니다 :-)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top