F
F
fgjcirifb2019-03-01 13:38:12
PHP
fgjcirifb, 2019-03-01 13:38:12

Best way to generate text?

There is a text. We need to make it dynamic. In the text we mark something like variables, for example {{ name }}. We also need support for conditional expressions like [if asddada][/if]. Well, then we generate it based on the values ​​of the variables. I'm thinking of using Markdown Extra for this purpose. Do you think this is normal? I wanted to use Laravel Blade, but it no longer supports compilation directly via a string (give it a file name).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2019-03-01
@HeadOnFire

IMHO, if you write your bike, it will be enough:
1. Choose the same format, curly {} means curly everywhere, square [] means square everywhere.
2. Look for occurrences with a simple regular expression.
3. Tokenize the found occurrences and execute your logic.
But it's better to take a ready-made solution, they are. Here's a quick search on packagist.org that turned up:
https://packagist.org/packages/aymanrb/php-unstruc...
https://packagist.org/packages/zualex/parsertext
and dozens more libs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question