cut_str 질문입니다.
본문
function search_cloud()
{
global $g5;
$pop_array = array();
$date_gap = date("Y-m-d", G5_SERVER_TIME - (60));
$sql = "select pp_word, count(*) as cnt from {$g5['popular_table']}
where pp_date between '$date_gap' and '".G5_TIME_YMD."'
group by pp_word
order by pp_id desc, pp_word
limit 0, ".G5_SC_POP_CNT;
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++){
$pop_array[$row[pp_word]] = $row[cnt];
}
return G5_SC_STYLE.tag_cloud($pop_array).'</div>';
}
//출처 https://youtu.be/iHxU6EAp6b4
function tag_cloud($tags)
{
$maxsize = G5_SC_MAXSIZE;
$minsize = G5_SC_MINSIZE;
$maxval = max(array_values($tags));
$minval = min(array_values($tags));
$spread = ($maxval - $minval);
$step = (($maxsize - $minsize) / $spread);
$str = '';
foreach($tags as $key => $value){
$size = round($minsize + (($value - $minval) * $step));
$str .= '<a href="'.G5_BBS_URL.'/search.php?sfl=wr_subject&sop=and&stx='.urlencode($key).'" style="font-size:'.$size.'px">'.$key.'</a> , ';
}
return $str;
}
}
$key 를 20글자내로 줄일려고 하는데요.
$str .= '<a href="'.G5_BBS_URL.'/search.php?sfl=wr_subject&sop=and&stx='.urlencode($key).'" style="font-size:'.$size.'px">'.$key.'</a> , ';
여기 마지막 '.$key.' 을 <?php echo cut_str($key, 20)?> 로 바꿨는데 안되요. 어떻게 하면 결과값을 20자 내로 줄일수 있을까요?
답변 2
전체 코드입니다.
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
if ($is_mobile) {
//ver1.0 150608 @_untitle_d
//글꼴 크기 px
define('G5_SC_MAXSIZE', 22); //maxsize
define('G5_SC_MINSIZE', 12); //minsize
define('G5_SC_POP_CNT', 20); //검색어 몇개
define('G5_SC_DATE_CNT', 7); //몇일 동안
define('G5_SC_STYLE', '<div style="margin:0 auto;width:100%;padding:3px;text-align:left;">');
function search_cloud()
{
global $g5;
$pop_array = array();
$date_gap = date("Y-m-d", G5_SERVER_TIME - (60));
$sql = "select pp_word, count(*) as cnt from {$g5['popular_table']}
where pp_date between '$date_gap' and '".G5_TIME_YMD."'
group by pp_word
order by pp_id desc, pp_word
limit 0, ".G5_SC_POP_CNT;
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++){
$pop_array[$row[pp_word]] = $row[cnt];
}
return G5_SC_STYLE.tag_cloud($pop_array).'</div>';
}
//출처 https://youtu.be/iHxU6EAp6b4
function tag_cloud($tags)
{
$maxsize = G5_SC_MAXSIZE;
$minsize = G5_SC_MINSIZE;
$maxval = max(array_values($tags));
$minval = min(array_values($tags));
$spread = ($maxval - $minval);
$step = (($maxsize - $minsize) / $spread);
$str = '';
foreach($tags as $key => $value){
$size = round($minsize + (($value - $minval) * $step));
$str .= '<a href="'.G5_BBS_URL.'/search.php?sfl=wr_subject&sop=and&stx='.urlencode($key).'" style="font-size:'.$size.'px">'.$key.'</a> , ';
}
return $str;
}
} else {
//ver1.0 150608 @_untitle_d
//글꼴 크기 px
define('G5_SC_MAXSIZE', 22); //maxsize
define('G5_SC_MINSIZE', 12); //minsize
define('G5_SC_POP_CNT', 60); //검색어 몇개
define('G5_SC_DATE_CNT', 7); //몇일 동안
define('G5_SC_STYLE', '<div style="margin:0 auto;width:100%;padding:3px;text-align:left;">');
function search_cloud()
{
global $g5;
$pop_array = array();
$date_gap = date("Y-m-d", G5_SERVER_TIME - (60));
$sql = "select pp_word, count(*) as cnt from {$g5['popular_table']}
where pp_date between '$date_gap' and '".G5_TIME_YMD."'
group by pp_word
order by pp_id desc, pp_word
limit 0, ".G5_SC_POP_CNT;
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++){
$pop_array[$row[pp_word]] = $row[cnt];
}
return G5_SC_STYLE.tag_cloud($pop_array).'</div>';
}
//출처 https://youtu.be/iHxU6EAp6b4
function tag_cloud($tags)
{
$maxsize = G5_SC_MAXSIZE;
$minsize = G5_SC_MINSIZE;
$maxval = max(array_values($tags));
$minval = min(array_values($tags));
$spread = ($maxval - $minval);
$step = (($maxsize - $minsize) / $spread);
$str = '';
foreach($tags as $key => $value){
$size = round($minsize + (($value - $minval) * $step));
$str .= '<a href="'.G5_BBS_URL.'/search.php?sfl=wr_subject&sop=and&stx='.urlencode($key).'" style="font-size:'.$size.'px">'.$key.'</a> , ';
}
return $str;
}
}
?>
오잉?
$str .= '<a href="'.G5_BBS_URL.'/search.php?sfl=wr_subject&sop=and&stx='.urlencode($key).'" style="font-size:'.$size.'px">'.cut_str($key, 20).'</a> , ';
이렇게 하니까 되네요.