Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

engrlaravel's avatar

Replace all parameter variables with values in string templates

I have templates for emails, I want to replace all occurrences with variable values in the template. Example:

$template = <p>Hi {applicant_name},</p>
            <br>
            <p>You are welcomed to {org_name}</p>, Your salary is {salary}
            <br>
            <p>
            -<br>{company_name}</p>

I have

 $applicant_name = "John";
 $org_name  = "ITF";
 $salary = 50000
 $company_name = "ABC"

How i can do it in laravel with a single function? I want to replace template of variables with real variable names.

0 likes
1 reply

Please or to participate in this conversation.