2014-03-26 1 views
0

이 기능을 사용하는 제목의 크기를 조정해야하지만 다음과 같이 작동합니다. car ... for ... 1991 1991 TOYOTA 1.6 16 VALF 15 개의 단어로 제한하고 싶습니다. 기능 제목 크기 조정 doesnt work 2

function title_resize($text, $max_length = 15, $fulltext = false) 
{ 
    global $db; 
    (string) $display_output = null; 

    $text = $db->add_special_chars($text); 

    if ($fulltext) 
    { 
     $output = (strlen($text) > $max_length) ? substr($text, 0, $max_length - 3) . '... ' : $text; 
    } 
    else 
    { 
     $text_words = explode(' ', $text); 

     $nb_words = count($text_words); 

     for ($i=0; $i<$nb_words; $i++) 
     { 
      $display_output[] = (strlen($text_words[$i]) > $max_length) ? substr($text_words[$i], 0, $max_length-3) . '... ' : $text_words[$i]; 
     } 

     $output = $db->implode_array($display_output, ' ', true, ''); 
    } 

    return $output; 
} 

어떻게 이런 짓을 할 수

: 여기 car for sale 1... 내 코드인가? (이 항목은 구경에게입니다 ...) USAC : <?=title_resize($item_details['name']);?>

+0

어떤 오류가 발생합니까? – Zeeshan

답변

0

어쩌면 내가 질문을받지 못했습니다 내가 원하는 15 개 단어와 디스플레이 내가이 같이하고 싶은 3 점 제한 제목입니다 그러나 이것은 예상 된 결과입니까?

function title_resize($text, $max_length = 15, $fulltext = false) 
{ 
    if ($fulltext) 
    { 
     return $text; 
    } 
    else 
    { 
     return substr($text, 0, $max_length) . '...'; 
    } 
} 

$str = "this item is for sale"; 

var_dump(title_resize($str, 10)); 
0
function title_resize($title, $length){ 
    return substr($title, 0, $length) . '...'; 
} 
0

시도해보십시오 .... 지정된 길이보다 큰 텍스트가있는 경우 점만 표시됩니다.

<?php 
function title_resize($text, $length = ''){ 
    $length = (empty($length)) ? 15 : $length; 
    $New_title = substr($text, 0, $length); 
    if(strlen($text) > $length) 
    { 
     $New_title .= "..."; 
    } 
    return $New_title; 
} 
echo title_resize("this will only show fifteen characters"); 
?> 
0

감사합니다 친구는 나는이 같은 뭔가했다 : 작동 을하지만 난 원래 대구에서 뭔가를 잃어 버릴 경우 내가 두려워?

function title_resize($text, $max_length = 15, $fulltext = false) 
{ 
    global $db; 
    (string) $display_output = null; 
    $text = $db->add_special_chars($text); 
    if ($fulltext) 
    { 
    $output = $text;   
    } 
    else 
    { 
     $output = (strlen($text) > $max_length) ? substr($text, 0, $max_length) . '... ' : $text; 

    } 
    return $output; 
}