mr-fan Posted September 15, 2015 Share Posted September 15, 2015 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 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 More sharing options...
bernhard Posted September 15, 2015 Share Posted September 15, 2015 On mobile. You can use wire('log')->save('debug', $yourVar); Or var_dump(...); And/or die(); Or chromephp logger. 1 Link to comment Share on other sites More sharing options...
SiNNuT Posted September 15, 2015 Share Posted September 15, 2015 Maybe Teppo's article can help: http://www.flamingruby.com/blog/taking-apart-a-simple-textformatter-module/ It's from 2013 but it still is all valid i think. 1 Link to comment Share on other sites More sharing options...
mr-fan Posted September 16, 2015 Author Share Posted September 16, 2015 Thank you Sinnut...This is a great tutorial! Best regards mr-fan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now