I have a string of file_get_contents()
which I simplify structures as follows:
$string = '
welcome in
admin panel
//start>license[version(lite)]
lite
//end>license[version(lite)]
//start>license[version(professional)]
professional
//end>license[version(professional)]
//start>license[version(enterprise)]
enterprise
//start>license[custom(company1)]
+ custom company1
//end>license[custom(company1)]
//start>license[custom(company2)]
+ custom company2
//end>license[custom(company2)]
//end>license[version(enterprise)]
version
1.4.2
';
I want to generate a final result like this
welcome in
admin panel
professional
version
1.4.2
I have tried to create a function to make logic for searching [version(professional)]
like this:
$lines = explode("n", $string);
$output = '';
$insideLicense = false;
foreach ($lines as $line) {
if (strpos($line, "//start>license[version(professional)]") !== false) {
$insideLicense = true;
continue;
}
if (strpos($line, "//end>license[version(professional)]") !== false) {
$insideLicense = false;
continue;
}
$output .= $line . "n";
}
dd($output);
but my result is:
welcome in
admin panel
//start>license[version(lite)] <-- remove this
lite <-- remove this
//end>license[version(lite)] <-- remove this
professional
//start>license[version(enterprise)] <-- remove this
enterprise <-- remove this
//start>license[custom(company1)] <-- remove this
+ custom company1 <-- remove this
//end>license[custom(company1)] <-- remove this
//start>license[custom(company2)] <-- remove this
+ custom company2 <-- remove this
//end>license[custom(company2)] <-- remove this
//end>license[version(enterprise)] <-- remove this
version
1.4.2
I want the <-- remove this
to be removed, and the final result is:
welcome in
admin panel
professional
version
1.4.2
can you help me, please? thank you…
2
Answers
I finally discovered the solution, add more logic like this:
and my full logic is like this:
or if you guys have a simpler solution, please let me know that.
Here is the compact solution.