Esempio n. 1
0
$t1 = microtime(true);
$xml = TextFormatter::parse($text);
$t2 = microtime(true);
$html = TextFormatter::render($xml);
$t3 = microtime(true);
printf("%6s µs - Parsing rich text for the second time\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Rendering rich text for the second time\n", round(1000000 * ($t3 - $t2)));
$text = 'Hello, world!';
$t1 = microtime(true);
$xml = TextFormatter::parse($text);
$t2 = microtime(true);
$html = TextFormatter::render($xml);
$t3 = microtime(true);
printf("%6s µs - Parsing plain text\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Rendering plain text\n", round(1000000 * ($t3 - $t2)));
$text = str_repeat("A line of [b]rich[/b] text\n", 200);
$t1 = microtime(true);
$xml = TextFormatter::parse($text);
$t2 = microtime(true);
$html = TextFormatter::render($xml);
$t3 = microtime(true);
printf("%6s µs - Parsing 200 lines of rich text\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Rendering 200 lines of rich text\n", round(1000000 * ($t3 - $t2)));
$text = str_repeat(":) ", 1000);
$t1 = microtime(true);
$xml = TextFormatter::parse($text);
$t2 = microtime(true);
$html = TextFormatter::render($xml);
$t3 = microtime(true);
printf("%6s µs - Parsing 1000 emoticons\n", round(1000000 * ($t2 - $t1)));
printf("%6s µs - Rendering 1000 emoticons\n", round(1000000 * ($t3 - $t2)));
Esempio n. 2
0
<?php

// Get the autoloader (unless you have already loaded Composer's)
include __DIR__ . '/../../src/autoloader.php';
// Use the Forum bundle. It supports BBCodes, emoticons and autolinking
use s9e\TextFormatter\Bundles\Forum as TextFormatter;
// Original text
$text = "Hello, [i]world[/i] :)\nFind more examples in the [url=https://github.com/s9e/TextFormatter/tree/master/docs/Cookbook]Cookbook[/url].";
// XML representation, that's what you should store in your database
$xml = TextFormatter::parse($text);
// HTML rendering, that's what you display to the user
$html = TextFormatter::render($xml, ['EMOTICONS_PATH' => '/path/to/emoticons']);
echo $html, "\n";
// Outputs:
//
// Hello, <i>world</i> <img src="/path/to/emoticons/smile.png" alt=":)"><br>
// Find more examples in the <a href="https://github.com/s9e/TextFormatter/tree/master/docs/Cookbook">Cookbook</a>.