Faker\Generator::parse PHP Method

parse() public method

Replaces tokens ('{{ tokenName }}') with the result from the token method call
public parse ( string $string ) : string
$string string String that needs to bet parsed
return string
    public function parse($string)
    {
        return preg_replace_callback('/\\{\\{\\s?(\\w+)\\s?\\}\\}/u', array($this, 'callFormatWithMatches'), $string);
    }

Usage Example

Example #1
0
 public function testParseReturnsStringWithTokensReplacedByFormatters()
 {
     $generator = new Generator();
     $provider = new FooProvider();
     $generator->addProvider($provider);
     $this->assertEquals('This is foobar a text with foobar', $generator->parse('This is {{fooFormatter}} a text with {{ fooFormatter }}'));
 }