2011-11-11 12 views
0

こんにちは私はこのコードを持っていて、echo "</dd>\n", chr(20);に20文字しか何も選択しませんでした。 どこが間違っていますか?文字列で文字列を制限する

おかげ

class newsStory{ 
    var $title=""; 
    var $link=""; 
    var $description=""; 
    var $pubdate=""; 

    function show(){ 
     if($this->title){ 
      if($this->link){ 
       echo "<dt><a href=\"$this->link\">$this->title</a></dt>\n"; 
      }elseif($this->title){ 
       echo "<dt>$this->title</a></dt>\n"; 
      } 
      echo "<dd>"; 
      if($this->pubdate) 
       echo "<i>$this->pubdate</i> - "; 
      if($this->description) 
       echo "$this->description"; 
      echo "</dd>\n", chr(20); 
     } 
    } 
} 
+1

何が問題になりますか?何がうまくいかない?あなたの '$ this-> property'は二重引用符で囲まれた文字列の中に' {} 'のように囲むべきです: 'echo" {$ this-> pubdate} - ";' –

答えて

3

chr()は、パラメータとして与えられたASCII値を持つ文字を表示するために使用されます。あなたはおそらくsubstr()を使用して、文字列の一部(部分文字列)を表示できるようにします。

$characterLimit = 20; 
$the_string = "Whatever string it is you're wanting to display in a shortened version."; 
echo "</dd>\n", substr($the_string, 0, $characterLimit); 

は、あなたに必要なものを提供します。

+0

ありがとうございます –

関連する問題