Jump to content

Help getting started with textformatters


mr-fan
 Share

Recommended Posts

Hi i'm testing some things with textformatters.

I did buy profields to get autolink as a learning base but this seems to be to complicated for me/my skills.

So like always i try to start from the basics...so like often i'm stucked :lol:

just created a easy textformatter that does some replacement on special tags - i looked at some other textformatters before i setuo this.

My Question is how i could debug such things within a textformatter i only get PHP errors but how could i test the output.

Is there any better commented example or explanation/docs on this topic?

What i need is to search textfields for special tags that start with || and end with || could be a word or phrase like ||example|| or ||other example||  - i wanna replace the inner string complete...

what i've until now is:

    /**
     * For the Textformatter interface
     *
     */
    public function format(&$str) {

        $openTag = '\|\|';
        $closeTag = '\|\|';


        $matches = array();
        $general_pattern = sprintf('/%s(.*?)%s/', $openTag, $closeTag);

        preg_match_all($general_pattern, $str, $matches);

        foreach ($matches[1] as $match) {

                //wanna replace the whole tag ||test|| should  be only test
                $search = $openTag.$match.$closeTag;

                //don't work like expected
                $str = str_replace($search, "test", $str);

                //works the part inside the tags are changed ||test|| on every match
                //$str = str_replace($match, "test", $str);

                //works for testing show all matches are correct after the textfield output
                $str .= $match.' ';
        }
    }

any hint in the right directions would be great.

Best regards mr-fan

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...