I have a simple PHP function for testing:
<?php
function MyOwnFunction($CaseType, $HashType, $OrgStr) {
if ($CaseType == 'u') {
$NewStr = strtoupper($OrgStr);
}
if ($CaseType == 'l') {
$NewStr = strtolower($OrgStr);
}
if ($HashType == 'md5') {
$OutStr = md5($NewStr);
}
if ($HashType == 'sha1') {
$OutStr = sha1($NewStr);
}
return $OutStr;
}
?>
All data is general.
I have this simple text-block:
[/a_1]Lorem ipsum dolor sit amet, consectetur adipiscing elit.[a_1/]
Phasellus et commodo ligula.
[/b_2]Nulla finibus posuere nisl, ut ultrices dolor.[b_2/]
[/c_3]Fusce dignissim tincidunt dui id imperdiet.[c_3/]
Donec venenatis ipsum lacus, sit amet posuere enim gravida et.
---
[a_1] = u : md5.
[c_3] = l : sha1.
I call this text block as a PHP varible: $MyTextBlock
.
Now, I want to create a new PHP function: NewTestFunction
, which parse the $MyTextBlock
. The output text, which is equivalent with running MyOwnFunction('u', 'md5', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
and MyOwnFunction('l', 'sha1', 'Fusce dignissim tincidunt dui id imperdiet.');
. And, bellow is a returned text, which I want to have:
958bbb39b883fb80e852db91d15a80ca
Phasellus et commodo ligula.
[/b_2]Nulla finibus posuere nisl, ut ultrices dolor.[b_2/]
f98503d5c5cc6355895e049f5b0676d54588a6d6
Donec venenatis ipsum lacus, sit amet posuere enim gravida et.
---
[a_1] = u : md5.
[c_3] = l : sha1.
How to parse this text-block as parameters of a function, in PHP? Is there any suggestion for me?
This question is not duplicated with any available question: my question is about the regex; and, an other question is about the equals.