<?php
/**
 * QQ空间文本辅助类
 */
class QzoneHelper
{
    /**
     * 随机取一行文本（支持 \r\n / \n）
     */
    public static function randLine($content)
    {
        $content = (string)$content;
        if ($content === '') return '';
        $lines = preg_split('/\r\n|\n|\r/', $content);
        $lines = array_values(array_filter(array_map('trim', $lines), function ($v) {
            return $v !== '';
        }));
        if (empty($lines)) return '';
        return $lines[array_rand($lines)];
    }

    /**
     * 解析基础占位与转义
     */
    public static function parseContent($content)
    {
        $text = (string)$content;
        if ($text === '') return '';
        $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
        $text = str_replace(["\r\n", "\r"], "\n", $text);
        $text = str_replace(['[换行]', '\n'], "\n", $text);
        return trim($text);
    }
}

