PHP 迷你纺织类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 迷你纺织类相关的知识,希望对你有一定的参考价值。

<?php

class TextiLite{
    
    /*
        TextiLite:
            A lightweight version of Textile built with PHP by Evan Walsh
            Version 001

        Based on the work of:
            http://codeigniter.com/wiki/BBCode_Helper/
            http://codeigniter.com/forums/viewthread/69615/
            
        Supports:
            <br/> by the way of newline
            *Text* => <strong>Text</strong>
            _Text_ => <em>Text</em>
            !http://image.url! => <img src="http://image.url"/>
            "Text":http://text.url => <a href="http://text.url" title="Text">Text</a>
    */

    function paragraph($text){
        $paragraphs = explode("\n\n", $text);
        $output = null;
        foreach($paragraphs as $paragraph) {
            $output .= "\n<p>".$paragraph."</p>\n";
        }
        return $output;
    }

    function textile($text = null){
        $regex = array(
            '/(.+)\n(.+)/',
            '/\*([^\*]+)\*/',
            '/\_([^\*]+)\_/',
            '/(!)((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))(!)/',
            '/(")(.*?)(").*?((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))/', 
        ); 
        $replace = array(
            "$1<br/>$2",
            "<strong>$1</strong>",
            "<em>$1</em>",
            "<img src=\"$2\"/>",
            "<a href=\"$4\" title=\"$2\">$2</a>",
        ); 
        return preg_replace($regex,$replace,$text);
    }
    
    function process($text){
        $text = $this->paragraph($text);
        $text = $this->textile($text);
        return $text;
    }

}

?>

以上是关于PHP 迷你纺织类的主要内容,如果未能解决你的问题,请参考以下文章

PHP 解析纺织

php 迷你推车迷你

数据分析类数据分析@Cache-Cache-上海 | 海归·数学/统计/服装纺织专业

php 迷你管理员吧

php WooCommerce迷你购物车项目计数和短代码

正则表达式剪贴板类(迷你模板引擎)