{"id":27199384,"url":"https://github.com/angelk/bbcode","last_synced_at":"2025-11-06T20:04:12.535Z","repository":{"id":6830134,"uuid":"8078410","full_name":"angelk/bbCode","owner":"angelk","description":null,"archived":false,"fork":false,"pushed_at":"2020-05-15T20:59:12.000Z","size":40,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T20:58:47.993Z","etag":null,"topics":["bbcode","bbcodeparser","parser","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/angelk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-07T18:07:02.000Z","updated_at":"2020-10-30T21:12:26.000Z","dependencies_parsed_at":"2022-09-18T11:53:24.247Z","dependency_job_id":null,"html_url":"https://github.com/angelk/bbCode","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angelk%2FbbCode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angelk%2FbbCode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angelk%2FbbCode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angelk%2FbbCode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/angelk","download_url":"https://codeload.github.com/angelk/bbCode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111942,"owners_count":21049577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bbcode","bbcodeparser","parser","php"],"created_at":"2025-04-09T20:58:50.866Z","updated_at":"2025-11-06T20:04:07.477Z","avatar_url":"https://github.com/angelk.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BB code parser for php 7.0+\n\nBuilds:\n\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/054684fa-c2d1-4cc3-8905-d4a797961c22/big.png)](https://insight.sensiolabs.com/projects/054684fa-c2d1-4cc3-8905-d4a797961c22)\n\n[![Build Status](https://travis-ci.org/angelk/bbCode.svg?branch=jenkins-integrati)](https://travis-ci.org/angelk/bbCode)\n\nThere are two parts - tokenizer and parser.\n\nTokenization - convert string to tokens.\n\nBbCodeParser - convert bbCodeTokens to html (+ some validations)\n\n# The Easy Way\n```php\n$tokenizer = new \\Potaka\\BbCode\\Tokenizer\\Tokenizer();\n\n$bbText = '[b]bold[/b]text[u]under[i]line[/i][/u]';\n\n$tokenized = $tokenizer-\u003etokenize($text);\n$factory = new  \\Potaka\\BbCode\\Factory();\n$bbcode = $factory-\u003egetFullBbCode();\n$html = $bbcode-\u003eformat($tokenized);\n```\n\nThe value if `html` is\n```html\n\u003cb\u003ebold\u003c/b\u003etext\u003cu\u003eunder\u003ci\u003eline\u003c/i\u003e\u003c/u\u003e\n```\n\n# Installation\n```\ncomposer require potaka/bbcode\n```\n\n# Internal explanation\n\n## Tokenization\nFor example\n```\n$bbText = '[b]bold[/b]text[u]under[i]line[/i][/u]';\n```\n\nWill be tokenized to\n```yml\nTag:\n  type: null,\n  tags:\n    tag1:\n      type: b\n      tags:\n        tag1:\n          type: null\n          text: bold\n    tag2:\n      type: null\n      text: text\n    tag3:\n      type: u\n      tags:\n        tag1:\n          type: null,\n          text: under\n        tag2:\n          type: i\n          tags:\n            tag1:\n              type: null,\n              text: line\n```\n\n## Tokenized to html\nYou need to have valid `bb code tags`. Build in tags are available in https://github.com/angelk/bbCode/tree/master/src/Potaka/BbCode/Tag\n\nBuilding the parser:\n```php\nuse Potaka\\BbCode;\nuse Potaka\\BbCode\\Tokenizer;\n\nuse Potaka\\BbCode\\Tag\\Bold;\nuse Potaka\\BbCode\\Tag\\Underline;\nuse Potaka\\BbCode\\Tag\\Italic;\n\nuse Potaka\\BbCode\\Tag\\Link;\n\n$bbcode = new BbCode();\n```\n\nLets add the `b` code\n```\n$bold = new Bold();\n$bbcode-\u003eaddTag($bold);\n```\n\nLets format the token from above\n\n```\n$tokenizer = new Tokenizer();\n$tokenized = $tokenizer-\u003etokenize($bbText);\n\n$bbcode-\u003eformat($tokenized);\n```\n\nwill return\n```\n\u003cb\u003ebold\u003c/b\u003etext[u]under[i]line[/i][/u]\n```\n\n`u` and `i` are not formated cuz tags are not added.\n\nLets add em.\n\n```\n$underline = new Underline();\n$bbcode-\u003eaddTag($underline);\n\n$italic = new Italic();\n$bbcode-\u003eaddTag($italic);\n```\n\nTest again\n```\n$bbcode-\u003eformat($tokenized);\n```\nResult:\n```html\n\u003cb\u003ebold\u003c/b\u003etext\u003cu\u003eunder[i]line[/i]\u003c/u\u003e\n```\n\nWhy `i` is not converted? Cuz `u` doesn't allow child tag of type `i`. Lets fix this\n```\n$bbcode-\u003eaddAllowedChildTag($underline, $italic);\n```\n\nEverything should work now!\n\nWhats the purpose of this allowing? Imagine you have link `[url]http://google.bg[/url]`.\nWhat if someone try to put link in link `[url=http://google.bg]google.[url=http://gmail.com]bg[/url][/url]`?\nThis will generate\n```html\n\u003ca href=\"http://google.bg\"\u003e\n  google.\u003ca href=\"http://gmail.com\"\u003ebg\u003c/a\u003e\n\u003c/a\u003e\n```\nThis html is invalid. It could even provide [xss](https://en.wikipedia.org/wiki/Cross-site_scripting). This is why you should not allow `url` inside `url`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangelk%2Fbbcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangelk%2Fbbcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangelk%2Fbbcode/lists"}