PHP automatic list creation from a textfile to (X)HTML -
I am creating a CMS as you already know, and now I have a problem with Lil.
We say: I have a text file:
[b] some bold text [/ b] [i] italic [/ i] - list item 1 - List item 2 - list item 3 # list item 1 # list item 2 # list item 3 and I want to change it to:
& Lt; B & gt; Some bold text & lt; / P & gt; & Lt; I & gt; Italic & lt; / I & gt; & Lt; Ul & gt; & Lt; Li & gt; List item 1 & lt; / Li & gt; & Lt; Li & gt; List item 2 & lt; / Li & gt; & Lt; Li & gt; List item 3 & lt; / Li & gt; & Lt; / Ul & gt; & Lt; Ol & gt; & Lt; Li & gt; List item 1 & lt; / Li & gt; & Lt; Li & gt; List item 2 & lt; / Li & gt; & Lt; Li & gt; List item 3 & lt; / Li & gt; & Lt; / Ol & gt; Bold and italic work (with Reggae), but how do I list?
'-' The list should be changed
- >
pre & lt; & Lt; Li & gt; List item 1 & lt; / Li & gt; & Lt; Li & gt; List item 2 & lt; / Li & gt; & Lt; Li & gt; List item 3 & lt; / Li & gt; & Lt; / Ul & gt; and in the '#' list
& lt; Ol & gt; & Lt; Li & gt; List item 1 & lt; / Li & gt; & Lt; Li & gt; List item 2 & lt; / Li & gt; & Lt; Li & gt; List item 3 & lt; / Li & gt; & Lt; / Ol & gt; Do anyone have experience with this? Please help me. I am using PHP 5.2.9
if you do not want to use an existing parsing library You have to parse the file line from the line and keep the current position somewhere.
If the lines start, and the state tells you that you are not already on a list, then a & lt; Ul> plus a & lt; Li> If you are already in a list, then just & lt; Li> put it.
The only thing with the rows starting with "#".
Comments
Post a Comment