0

このコードを取得しました

       $title = new FullName($reservation->Title, $reservation->Description)

ボックス内に Title と Description の値が表示されますが、互いに直接続いています。ボックスが小さすぎる場合、改行が行われますが、ボックスの最後の正確なポイントでのみ行われます。では、どうすれば $reservation->Title と $reservation->Description の間に改行を強制できますか?

フルネームクラスはこちら

        class FullName
        {
/**
 * @var string
 */
private $fullName;

public function __construct($firstName, $lastName)
{
    $formatter = Configuration::Instance()->GetKey(ConfigKeys::NAME_FORMAT);
    if (empty($formatter))
    {
        $this->fullName = "$firstName $lastName";
    }
    else
    {
        $this->fullName = str_replace('{first}', $firstName, $formatter);
        $this->fullName = str_replace('{last}', $lastName, $this->fullName);
    }
}

public function __toString()
{
    return $this->fullName;
}

}

4

3 に答える 3

0

実際の例については、リンクを参照してください: http://codepad.viper-7.com/qS7nNv

クラスに 3 番目のパラメータを追加できます。

class FullName
{
/**
 * @var string
 */
private $fullName;

public function __construct($firstName, $lastName, $delimiter = null)
{
    $formatter = Configuration::Instance()->GetKey(ConfigKeys::NAME_FORMAT);
    if (empty($formatter))
    {
      if($delimiter) {
        $this->fullName = "$firstName $delimiter $lastName";
      } else {
        $this->fullName = "$firstName $lastName";
      }
    }
    else
    {
        $this->fullName = str_replace('{first}', $firstName, $formatter);
        $this->fullName = str_replace('{last}', $lastName, $this->fullName);
    }
}

public function __toString()
{
    return $this->fullName;
}
 }

次に区切り文字を追加します。

$title = new FullName($reservation->Title, $reservation->Description, "<br />");
于 2013-01-28T13:59:40.930 に答える
0

適切な説明がなければ良い方法ではありませんが、簡単な解決策

交換

$title = new FullName($reservation->Title, $reservation->Description)

   $t = $reservation->Title . "<br />";
   $d = $reservation->Description;
   $title = new FullName($t, $d);
于 2013-01-28T13:46:49.557 に答える
0

HTML 改行は次のように挿入できます。

$this->fullName = $firstName . '<br />' . $lastName

または一般的な (HTML 以外の) 改行文字を使用:

$this->fullName = $firstName . "\n" . $lastName

最後のケース (") では二重引用符を使用することが重要です。

于 2013-01-28T13:46:49.913 に答える