class Something
{
public static function compile(&$subject, $replace, $with) {
$placeholders = array_combine($replace, $with);
$condition = '{[a-z0-9\_\- ]+:[a-z_]+}';
$inner = '((?:(?!{/?if).)*?)';
$pattern = '#{if\s?('.$condition.')}'.$inner.'{/if}#is';
while (preg_match($pattern, $subject, $match)) {
$placeholder = $match[1];
$content = $match[2];
$subject = preg_replace($pattern,
empty($placeholders[$placeholder]) ? '' : addcslashes($content, '$'),
$subject,
1);
}
}
}
I have an area of html code to play. Dompdf processes the rest to convert my form to pdf. This code was almost prepared. It gives me the freedom to use;
{if {dil:value}} <div class="english">ENGLISH</div> {/if}
something similar in the html area. But he checked only empty or not. But I want to know which option is selected. So I want to use a code like this:
{if {dil:value}=='ENGLISH'} <div class="english">ENGLISH</div> {/if}
I converted an empty control string with a manual equality check to make sure it works;
$subject = preg_replace($pattern,
$placeholders[$placeholder]=='english' ? '' : addcslashes($content, '$'),
$subject,
1);
And it worked, but without freedom of course (only if the radio is equal to English). I am so new to regex, so I couldn’t understand. I tried to add the $ equality variable, so I would use my code many times with different checks;
class Something
{
public static function compile(&$subject, $replace, $with) {
$placeholders = array_combine($replace, $with);
$condition = '{[a-z0-9\_\- ]+:[a-z_]+}';
$inner = '((?:(?!{/?if).)*?)';
$equality = '(?<=~)[^}]*(?=~)';
$pattern = '#{if\s?('.$condition.')'.$equality.'}'.$inner.'{/if}#is';
while (preg_match($pattern, $subject, $match)) {
$placeholder = $match[1];
$content = $match[2];
$subject = preg_replace($pattern,
$placeholders[$placeholder]==$equality ? '' : addcslashes($content, '$'),
$subject,
1);
}
}
}
with this code in the html area;
{if {dil:value}~'ENGLISH'~} <div class="english">ENGLISH</div> {/if}
, , : PDF, pdf.
- $match. $match , . , ,
while (preg_match($pattern, $subject, $match)) {
$placeholder = $match[1];
$equality = $match[2];
$content = $match[3];
, - . , , .
.