So I'm actually storing an html field, but I'd like to add some pseudo tags to make it easier to publish. I.E. I want to wrap the title/headers into this tag: << ... >> E.G. << My Header >> Then I would enumerate them, format, and display the text beneath.
E.G.:
<<News>>
Breaking news on Sunday.
Have been taking hostages.
<<General Information>>
We would want to recieve our blabla.
And you want it.
<<User Suggestions>>
Yeah we want it so much...
Should actually display:
<H1 class="whatever" ID="Product_Header_1">News<H1>
Breaking news on Sunday.
Have been taking hostages.
<H1 class="whatever" ID="Product_Header_2">General Information</H1>
We would want to recieve our blabla.
And you want it.
<H1 class="whatever" ID="Product_Header_3">User Suggestion</H1>
Yeah we want it so much...
And then should return an array with actual headers and their number, so I could use it elsewhere on the page to make references.
So It seems we could either replace them directly, but that might get problematic with enumerating and returning the values, and would probably fail in case of not closed tags.
Or, to split them into into an array and then proceed manually, which seems like a better way to go.
This is what I tried so far:
$TEXT_A=preg_split('/<<([^>]+)>>/', $TEXT);
foreach($TEXT_A as $key => $val){
if ($key>0) echo "<br>-!-";
echo $val;
}
Where $TEXT is out HTML Text with pseudo-tags.
The problem though, split does not return the regexp match itself, so I'm getting puzzled on how to extract it. Maybe I would need to write some custom function that would return an array of texts AND headers, instead of regular split, but I don't know where to start...
Please help.