Problema classe per preview post

Jake Ikswez

Nuovo Utente
4 Dic 2013
3
0
0
Salve,
Ricevo questo errore Error was: Undefined variable: lineBreaks
Found in: classes//Applications/XAMPP/xamppfiles/htdocs/examProject/classes/preview.class.php, line 35
nella seguente classe creata per le anteprime dei testi dei post postati in un forum. Si tratta di un progetto scolastico.
grazie dell'aiuto ecco il codice:
PHP:
class Preview
{
    protected $maxCharacters;
    protected $maxLines;
    protected $encoding;
    protected $lineBreaks;

    public function __construct($maxCharacters = 500, $maxLines = 10, $encoding = 'UTF-8', array $lineBreaks = array("\r\n", "\r", "\n"))
    {
        $this->maxCharacters = $maxCharacters;
        $this->maxLines = $maxLines;
        $this->encoding = $encoding;
        $this->lineBreaks = $lineBreaks;
    }

    public function makePreview($text)
    {
        $text = $this->normalizeLinebreaks($text);

        // this prevents the breaking of the &quote; etc
        $text = html_entity_decode($text, ENT_QUOTES, $this->encoding);

        $text = $this->limitLines($text);

        if (mb_strlen($text, $this->encoding) > $this->maxCharacters) {
            $text = $this->limitCharacters($text);
        }

        return html_entity_decode($text, ENT_QUOTES, $this->encoding);
    }

    protected function normalizeLinebreaks($text)
    {
        return str_replace($lineBreaks, "\n", $text); //è qui che mi da l'errore ma non capisco perché
    }

    protected function limitLines($text)
    {
        $lines = explode("\n", $text);
        $limitedLines = array_slice($lines, 0, $this->maxLines);

        return implode("\n", $limitedLines);
    }

    protected function limitCharacters($text)
    {
        return substr($text, 0, $this->maxCharacters);
    }
}

$preview = new Preview();
echo $preview->makePreview('Some text which will be turned into a preview.');
 

Discussioni simili