이온디
호스팅센터
IT프리랜서 커뮤니티
스레드

더보기 php 코드

2025년 01월 31일

list.blade.php

v.1
@php
$maxLength350;
if(mb_strlen(strip_tags($document->getContent(false))) > $maxLength){
// $content = preg_replace('/<img[^>]*>/'''$document->variables['content']);
// $shortContent = mb_substr($content0$maxLength) . '...';
$fullUrl = getUrl('document_srl'$document->document_srl); // 문서의 URL 생성
$content$document->getSummary($maxLength);
$content .= " <a href='"$fullUrl"' class='read-more'>더보기</a>";
echo $content;
}else{
// echo '이하';
$content = preg_replace('/<img[^>]*>/'''$document->variables['content']);
//  echo $document->getContent(false);
echo $content;
}
@endphp


v.2 : 공백 제거하는 부분 추가함

@php
                         $maxLength = 350;
                         if(mb_strlen(strip_tags($document->getContent(false))) > $maxLength){
                            // $content = preg_replace('/<img[^>]*>/', '', $document->variables['content']);
                            // $shortContent = mb_substr($content, 0, $maxLength) . '...';
                            $fullUrl = getUrl('document_srl', $document->document_srl); // 문서의 URL 생성
                            $content = $document->getSummary($maxLength);
                            $content .= " <a href='" . $fullUrl . "' class='read-more'>더보기</a>";
                            echo $content;
                         }else{
//                          echo '이하';
//                          $content = preg_replace('/<p><br><\/p>/', '', $document->variables['content']);
                            $content = preg_replace('/<img[^>]*>/', '', $document->variables['content']);
                            $content = preg_replace('/<br\s*\/?>/i', '', $content);
//                           echo $document->getContent(false);
                            echo $content;
                         }
                      @endphp
 


내용을 입력하세요
0
댓글은 로그인 사용자만 작성 가능합니다. 로그인하기