들레아빠

게시판의 wr_link1에 유튜브(youtube) 주소가 있을때

33282748_1703478228.2629.png

[code]

<?php
$table = '유튜브게시판';
$sql = "select wr_id from g5_write_{$table} order by rand() limit 1";
$row = sql_fetch($sql);

$sql_yu = " select * from g5_write_{$table} where wr_id={$row['wr_id']} ";
$row_yu = sql_fetch($sql_yu);

$yu_cor = extractYouTubeVideoId($row_yu['wr_link1']);

$sqll = "SELECT wr_id, wr_link1 FROM g5_write_{$table}";
$result = sql_query($sqll);

while ($row = sql_fetch_array($result)) {
    $yu_co = extractYouTubeVideoId($row['wr_link1']);
}

function extractYouTubeVideoId($url) {
    $pattern = '/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/';
    preg_match($pattern, $url, $matches);
    return isset($matches[1]) ? $matches[1] : null;
}
$mode = $mode ? $mode : '1';
?>
<iframe id="" class="" src="https://www.youtube.com/embed/<?php echo ($mode == '1') ? $yu_cor : $yu_co;?>" title="<?php echo $row_yu['wr_subject']?>" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen=""></iframe>
<form method="get" style="float:right;position:relative;background:#a3b8c5;margin-top:-32.5px;padding:0px 5px 0px 15px;border-radius:30px 0 0 30px;border:1px solid #4a4a4a;opacity:.5">
    <button type="submit" style="padding:7px;background:transparent;border:0">
        <input type="radio" name="mode" value="1" <?php echo ($mode == '1') ? 'checked' : ''; ?>>
        랜덤보기
    </button>
    <button type="submit" style="padding:7px;background:transparent;border:0">
        <input type="radio" name="mode" value="2" <?php echo ($mode == '2') ? 'checked' : ''; ?>>
        최근보기
    </button>
</form>

[/code]

필요시 유튜브게시판 write.skin.php 수정

[code]

    <?php for ($i=1; $is_link && $i<=G5_LINK_COUNT; $i++) { ?>
    <div class="bo_w_link write_div">
        <label for="wr_link<?php echo $i ?>"><i class="fa fa-link" aria-hidden="true"></i><span class="sound_only"> 링크  #<?php echo $i ?></span></label>
        <input type="text" name="wr_link<?php echo $i ?>" value="<?php if($w=="u"){ echo $write['wr_link'.$i]; } ?>" id="wr_link<?php echo $i ?>" <?php if($i == 1) echo 'required'?> class="frm_input full_input <?php if($i == 1) echo 'required'?>" size="50" placeholder="<?php if($i == 1) echo '유튜브 주소를 입력하세요.'?>">
    </div>
    <?php } ?>

[/code]

게시판의 wr_link1에 유튜브주소를 최근 또는 랜덤으로 선택해서 홈에

출력하는 코드입니다.

|

댓글 4개

[code]

https://www.youtube.com/live/ClC5fBqyR6Q?si=KiHs8JVIMHOKhZrf
http s://


http s://

[/code]

wr_link1에 이러한 주소들을 ID만 추출하여 동작 합니다.

추천 하여 주신 bossbug님, evansh2016님, 낙엽지는새님 감사 합니다.

@코잉 네~ 감사 합니다.

댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

+
제목 글쓴이 날짜 조회
2년 전 조회 1,029
2년 전 조회 3,463
2년 전 조회 1,694
2년 전 조회 1,866
2년 전 조회 1,229
2년 전 조회 1,763
2년 전 조회 1,667
2년 전 조회 2,268
2년 전 조회 1,682
2년 전 조회 1,137
2년 전 조회 1,991
2년 전 조회 1,468
2년 전 조회 1,341
2년 전 조회 2,289
2년 전 조회 1,742
2년 전 조회 2,241
2년 전 조회 1,364
2년 전 조회 2,204
2년 전 조회 1,040
2년 전 조회 1,795
2년 전 조회 1,560
2년 전 조회 2,857
2년 전 조회 1,781
2년 전 조회 2,074
2년 전 조회 2,560
2년 전 조회 2,584
2년 전 조회 1,629
2년 전 조회 1,751
2년 전 조회 1,577
2년 전 조회 1,470