I'm pretty sure there are better ways, but considering the current situation I think we may do that little step further for sake of extendibility.
At the moment, in order to replace "change" a single BBC tag, we have to loop over the whole array, search for it and then do whatever we want, along the lines of:
for ($i = count($codes) - 1; $i > 0; $i--)
{
$code = &$codes[$i];
if ($code['tag'] == 'url')
{
What I was thinking is to slightly re-organize the codes so that they are simply grouped by tag, that way we'd have just to loop over the target tag instead of the whole array, something like:
'abbr' => array(
array(
self::ATTR_TAG => 'abbr',
self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
...
),
),
'anchor' => array(
array(
self::ATTR_TAG => 'anchor',
self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
...
),
),
'quote' => array(
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
...
),
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
...
),
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_EQUALS,
...
),
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
...
),
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
...
),
),
That way, to change the url tag we'll need to just loop over a small number of elements:
for ($i = count($codes['url']) - 1; $i > 0; $i--)
{
$code = &$codes[$i];
if ($code['tag'] == 'url')
{
Of course, that way, before use the tags in the parser code, we'll need to re-create the previous version of the array (unless even the code may take advantage of this structure.