News:

Wondering if this will always be free?  See why free is better.

Main Menu

Custom BBC tag code for php 7.2/3 compatibility

Started by spiros, March 09, 2019, 03:33:47 AM

Previous topic - Next topic

spiros

I have a custom tag and I want to adapt it (as done here). Is the way I do it correct?

Find
array(
'tag' => 'google',
'type' => 'unparsed_content',
'content' => '<a href="https://www.google.com/search?q=$1" target="_blank">$1</a>',
'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
                'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_content' => '<span style="color: red;">Google Search: $1</span>',
),
array(
'tag' => 'google',
'type' => 'unparsed_equals',
'before' => '<a href="https://www.google.com/search?q=$1" target="_blank">',
                'after' => '</a>',
                'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_before' => '<span style="color: red;">',
                'disabled_after' => ' ($1)</span>',
),


Replace

array(
'tag' => 'google',
'type' => 'unparsed_content',
'content' => '<a href="https://www.google.com/search?q=$1" target="_blank">$1</a>',
'validate' => function (&$tag, &$data, $disabled)
{
$data = strtr($data, array('<br>' => ''));
},
                'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_content' => '<span style="color: red;">Google Search: $1</span>',
),
array(
'tag' => 'google',
'type' => 'unparsed_equals',
'before' => '<a href="https://www.google.com/search?q=$1" target="_blank">',
                'after' => '</a>',
                'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_before' => '<span style="color: red;">',
                'disabled_after' => ' ($1)</span>',
),

RichardAD

That is the correct way to update your code from using

   create_function( <args-text>, <source-code-text>)

to using anonymous function

   function(args) { source code }
   
special attention should be made if the original source code text contained text escapes such as \' or \".  You can get pretty dizzy if the original source code text also contained regex patterns

Arantor

Generally that looks sound though the change of br format may bite you if not careful.

Advertisement: