Here I have an array and there is content situated inside it, their is either, one object, two, or more - depending on the tags required; the first element nested in the multidimensional array would be the textual output, unless it is an array, then the first element inside the array would be the text.
However, the other content in the array is in reference to the HTML tag they correspond to, such as:
[1] => Array
(
[0] => bo <====== Text to output
[1] => bold <====== tag to be within
)
However, in the module of simplicity, I would prefer for the content not to constantly repeat such responses, like:
This is a test <b>bo</b><i><b>ld</b></i><i>,</i> <u><i>u</i></u><u>nderline</u> ...
Instead the output should be:
This is a test<b>bo<i>ld</i></b><i>, <u>u</u></i><u>nderline</u> ...
This is the PHP code I have for it so far...
$use = array();
$base = "";
foreach ($build as $part => $data) {
// print_r($use);
if(!is_array($data)){
$base .= $data;
} else {
$text = array_shift($data);
if(!is_array($data[0])){
$data = array($data[0]);
} else {
$data = $data[0];
}
$removed = array_diff($use,$data);
foreach (($data) as $tag) {
if (in_array($tag, array_diff($use,$data))) {
$base .= "<\/" . $tag . ">";
} elseif(!in_array($tag, $use)){
$base .= "<" . $tag . ">";
array_push($use, $tag);
}
}
$use = $data;
$base .= $text;
}
}
print_r($base);
And here is the array if required (in JSON format!):
["This is a test
Including ",["bo","bold"],["ld",["italic","bold"]],[", ","italic"],["u",["underline","italic"]],["nderlined","underline"],", ",["strike-through","strike"],", and ",["italic","italic"],"
text:
",["numbered lists",["underline","strike","italic","bold"]],["
",[]],"as well as",["
",[]],["non ordered lists","http:\/\/test.com"],["
",[]],"it works very well",["
",[]],["try it","http:\/\/google.com"],"
",["http:\/\/google.com",["bold","http:\/\/google.com"]],"
",["wow","bold"],"
",["lol","bold"]]
Any help would be much appreciated... thanks!