PHP 오류를 해결하는 방법을 알 수 없습니다.
아래 코드에서 오류가 발생합니다.
치명적인 오류 : Cannot redeclare getintro () (이전에 선언 된 ... on line 94)
아래에 94 행을 표시했습니다. 어떤 도움이나 안내를 주시면 감사하겠습니다. 내 목표는 텍스트의 일부만 표시하고 데이터베이스의 각 행을 기반으로 각 블로그 게시물을 반복하는 것입니다. 링크를 클릭하면 blog.php에 댓글이있는 전체 블로그가 열립니다.
<?php // retreive post
include('php/config.php');
include ('php/function.php');
dbConnect();
$blog_query = mysql_query(
'SELECT *
FROM Blog
ORDER BY DATE DESC');
while($row = mysql_fetch_array($blog_query)):
$date = date_create($row['DATE']);
$str = $row['CONTENT'];
$ID = $row['ID'];
LINE 94 function getIntro($str, $count = 200) {
return preg_replace('/\s+?(\S+)?$/', '', substr(nl2br($str), 0, $count)) . " <a href=\"blog.php?page={$ID}\" class=\"changeColor\">Read more...</a>\n";
}
$new_string = getIntro($str);
?>
<div class="post">
<h2><?php echo $row['TITLE']?></h2>
<h3><?php echo date_format($date, 'l, F j, Y')?></h3>
<p><?php echo $new_string?></p>
</div>
</div>
<?php endwhile?>
함수가 루프 내부에서 선언되고 있습니다. 함수 선언을 루프 밖으로 이동합니다.
<?php // retreive post
include('php/config.php');
include ('php/function.php');
dbConnect();
$blog_query = mysql_query(
'SELECT *
FROM Blog
ORDER BY DATE DESC');
function getIntro($str, $count = 200) {
return preg_replace('/\s+?(\S+)?$/', '', substr(nl2br($str), 0, $count)) . " <a href=\"blog.php?page={$ID}\" class=\"changeColor\">Read more...</a>\n";
}
while($row = mysql_fetch_array($blog_query)):
$date = date_create($row['DATE']);
$str = $row['CONTENT'];
$ID = $row['ID'];
$new_string = getIntro($str);
?>
<div class="post">
<h2><?php echo $row['TITLE']?></h2>
<h3><?php echo date_format($date, 'l, F j, Y')?></h3>
<p><?php echo $new_string?></p>
</div>
</div>
<?php endwhile?>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다