Welcome Guest, Not a member yet? Register   Sign In
parsing custom tags
#1

[eluser]megabyte[/eluser]
I want to take a paragraph like so:

Lorem Ipsum is [simply] dummy text of the printing and [typesetting] industry. Lorem Ipsum has been the industry's [standard] dummy text ever since the 1500s.


Notice the words enclosed in square brackets.

I want to run a custom function on each word enclosed in these brackets.

I'm not great with regex but I know that will play a part.


Can anyone point me in the right direction?


Thanks
#2

[eluser]megabyte[/eluser]
Solved it:


Code:
<?php
$input = "the [quick] brown fox [ JUMPED] over the [Hedge]";

function parse_all_tags($input)
{
    $regex = '#\[(.*?)]#';

    // just as a test switch the brakets
    if (is_array($input)) {
        $input = '{'.$input[1].'}';
    }

    return preg_replace_callback($regex, 'parse_all_tags', $input);
}

$output = parse_all_tags($input);

echo $output;
?>




Theme © iAndrew 2016 - Forum software by © MyBB