GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - putchi/php-bbcode: A naive attempt at a BBCode "parser" written in PHP. It uses regex and thus fails at complex, nested tags.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

46 Commits
46 Commits

Folders and files

NameName
Last commit message
Last commit date
README.md
README.md
 
 
bbcode.php
bbcode.php
 
 
tests.php
tests.php
 
 

Repository files navigation

Instructions

  1. Include bbcode.php
  2. Instantiate the BBCode class
  3. Execute the toHTML method on a string which contains BBCode (optionally pass false as the second argument to allow special html chars like "<html_tag>...</html_tag>")
  4. Enjoy HTML output

Example Code

<?php
require "bbcode.php";

$text=<<<EOF

[br]

[b]This is bold text[/b]

[i]This is italic text[/i]

[p]this is a paragraph - some text goes here...[/p]

[code]This is pre-formatted text[/code]

[quote]This is a quote[/quote]

[quote="Obama"]This is a quote by a specific person[/quote]

[quote cite="https://www.google.com"]This is a quote[/quote]

[quote="Obama" cite="https://www.google.com"]This is a quote by a specific person[/quote]

[quote name="Obama"]This is a quote by a specific [q]person[/q][/quote]

[quote name="Obama" cite="https://www.google.com"]This is a quote by a specific person[/quote]

[size=30]This text's size is set at 30pt[/size]

[s]This text has a strikethrough[/s]

[u]This text is underlined.[/u]

[left]This text is to the left[/left]

[center]This text is centered[/center]

[right]This text is to the right[/right]

[color=red]This is red text[/color]

[email][email protected][/email]

[[email protected]]An e-mail link[/email]

[email subject=my subject][email protected][/email]

[[email protected] subject=my subject]An e-mail link with subject[/email]

[url]http://www.google.com/[/url]

[url=http://www.google.com/]Google.com yo![/url]

[img]http://i.imgur.com/WqYEO.jpg[/img]

An image as a link:

[url=http://en.wikipedia.org/wiki/Ninja][img]http://i.imgur.com/8d7Yu.jpg[/img][/url]

This is an unordered list: 

[list]
[*]list item #1
[*]list item #2
[*][b]bold list item #3[/b]
[/list]

This is an ordered (numbered) list: 

[list=1]
[*]list item #1
[*]list item #2
[*][b]bold list item #3[/b]
[/list]

This is an ordered (alpha) list: 

[list=a]
[*]list item #1
[*]list item #2
[*][b]bold list item #3[/b]
[/list]

[youtube]oRdxUFDoQe0[/youtube]

[youtube size=520X415]oRdxUFDoQe0[/youtube]

[youtube]https://www.youtube.com/watch?v=oRdxUFDoQe0[/youtube]

[youtube size=520X415]https://www.youtube.com/watch?v=oRdxUFDoQe0[/youtube]


EOF;

$bbcode = new BBCode;

//will close unclosed bbcode tags.
$formated_BBcode = $bbcode->checkTag($text);

echo $bbcode->toHTML($formated_BBcode);  

?>

Example Output

<br/>

<strong>This is bold text</strong>

<em>This is italic text</em>

<p>this is a paragraph - some text goes here...</p>

<pre><code>This is pre-formatted text</code><pre>

<blockquote><p>This is a quote</p></blockquote>

Obama wrote: <blockquote><p>This is a quote by a specific person</p></blockquote>

<blockquote cite="https://www.google.com"><p>This is a quote</p></blockquote>

Obama wrote: <blockquote><p>This is a quote by a specific <q>person</q></p></blockquote>

Obama wrote: <blockquote cite="https://www.google.com"><p>This is a quote by a specific person</p></blockquote>

<span style="font-size:30%">This text's size is set at 30%</span>

<del>This text has a strikethrough</del>

<span style="text-decoration:underline;">This text is underlined.</span>

<div style="text-align:left;">This text is centered</div>

<div style="text-align:center;">This text is centered</div>

<div style="text-align:right;">This text is centered</div>

<span style="color:red;">This is red text</span>

<a href="mailto:[email protected]">[email protected]</a>

<a href="mailto:[email protected]">An e-mail link</a>

<a href="mailto:[email protected]?subject=my subject">[email protected]</a>

<a href="mailto:[email protected]?subject=my subject">An e-mail link with subject</a>

<a href="http://www.google.com/">http://www.google.com/</a>

<a href="http://www.google.com/">Google.com yo!</a>

<img src="http://i.imgur.com/WqYEO.jpg"/>

An image as a link:

<a href="http://en.wikipedia.org/wiki/Ninja"><img src="http://i.imgur.com/8d7Yu.jpg"/></a>

This is an unordered list: 

<ul><li>list item #1</li><li>list item #2</li><li><strong>bold list item #3</strong></li></ul>

This is an ordered (numbered) list: 

<ol><li>list item #1</li><li>list item #2</li><li><strong>bold list item #3</strong></li></ol>

This is an ordered (alpha) list: 

<ol style="list-style-type: lower-alpha;"><li>list item #1</li><li>list item #2</li><li><strong>bold list item #3</strong></li></ol>

<iframe width="420" height="315" src="https://www.youtube.com/embed/oRdxUFDoQe0" frameborder="0" allowfullscreen></iframe>

<iframe width="520" height="415" src="https://www.youtube.com/embed/oRdxUFDoQe0" frameborder="0" allowfullscreen></iframe>

<iframe width="420" height="315" src="https://www.youtube.com/embed/oRdxUFDoQe0" frameborder="0" allowfullscreen></iframe>

<iframe width="520" height="415" src="https://www.youtube.com/embed/oRdxUFDoQe0" frameborder="0" allowfullscreen></iframe>

About

A naive attempt at a BBCode "parser" written in PHP. It uses regex and thus fails at complex, nested tags.

Resources

Readme
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.