Jump to content

dynamicaly create UL / OL from personalised tagged data


nadeemshafi9

Recommended Posts

hello guys i have a huge DB of data, we use <NUMBERLIST></NUMBERLIST> etc to define lists

 

at the moment it works for one list eg everything in <NUMBERLIST></NUMBERLIST> is converted to

 

<ol>

<li>hi</li>

<li>hi</li>

<li>hi</li>

</ol>

 

this is done by spliting the entire text by </NUMBERLIST> finding ARRAY ELEMENTS with <NUMBERLIST> finding the /n and replacing accordingly.

 

 

the task is to allow for multiple embedded lists eg

 

text text text text text text text text text text text text text text text text text text

text text text text text text text text text text text text text text text text text text

text text text text text text text text text text text text .

 

<ol>

<li>hi</li>

<li>hi</li>

<li>hi</li>

<ol>

<li>hi</li>

<li>hi</li>

<li>hi</li>

<ol>

<li>hi</li>

<li>hi</li>

<li>hi</li>

</ol>

</ol>

</ol>

 

text text text text text text text text text text text text text text text text text text

text text text text text text text text text text text text text text text text text text

text text text text text text text text text text text text .

 

<ol>

<li>hi</li>

<li>hi</li>

<li>hi</li>

<ol>

<li>hi</li>

<li>hi</li>

<li>hi</li>

<ol>

<li>hi</li>

<li>hi</li>

<li>hi</li>

</ol>

</ol>

</ol>

 

 

i have tried numerous ways but have had no luck, any suggestions please, im writing pseudo before any code.

 

HERE IS THE DATA RAW

 

tatum deliquat augait, quis nismodigna feu feu feum dolor amconum do coreetummy nim velismodiam dipsusc ipsuscil et ip eliquat. Ut wis nim vulland ionsecte vel ulpute venimet,conulput autpat wisl ulputat er sim nonulla mcommy nonsequ issequatem quat verostrud digna corper sequisi.

Duis am inibh erat ute min etumsandrem quam quis erat, vent praestrud minit nullaoreet, veliqui ssisit nonsequate tet num quipsumsan henit wis nis nit utet veraesed et adit nulpute ver autpat. Ut at, velis nos am do odolorper summy num zzriustio odigna con eum zzrilis adipismolor am irit lam, commy nim zzril ullamconsent ullutpat wis eniatet, sim veleseniat, coreetue dolesequi tet nulput nulputpate miniamc onsequismod min hent p

 

test

<NUMBERLIST>

test1

test1

test1

<NUMBERLIST>

test2

test2

test2

<NUMBERLIST>

test3

test3

test3

<NUMBERLIST>

test4

test4

test4

<NUMBERLIST>

test5

test5

test5

<NUMBERLIST>

test6

test6

test6

<NUMBERLIST>

test7

test7

test7

<NUMBERLIST>

test8

test8

test8

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

 

tatum deliquat augait, quis nismodigna feu feu feum dolor amconum do coreetummy nim velismodiam dipsusc ipsuscil et ip eliquat. Ut wis nim vulland ionsecte vel ulpute venim et, conulput autpat wisl ulputat er sim nonulla mcommy nonsequ issequatem quat verostrud digna corper sequisi.

Duis am inibh erat ute min etumsandrem quam quis erat, vent praestrud minit nullaoreet, veliqui ssisit nonsequate tet num quipsumsan henit wis nis nit utet veraesed et adit nulpute ver autpat. Ut at, velis nos am do odolorper summy num zzriustio odigna con eum zzrilis adipismolor am irit lam, commy nim zzril ullamconsent ullutpat wis eniatet, sim veleseniat, coreetue dolesequi tet nulput nulputpate miniamc onsequismod min hent p

 

 

test

<NUMBERLIST>

test1

test1

test1

<NUMBERLIST>

test2

test2

test2

<NUMBERLIST>

test3

test3

test3

<NUMBERLIST>

test4

test4

test4

<NUMBERLIST>

test5

test5

test5

<NUMBERLIST>

test6

test6

test6

<NUMBERLIST>

test7

test7

test7

<NUMBERLIST>

test8

test8

test8

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

</NUMBERLIST>

Thanks

bow to thine master

 

 

$p1 = 0;

$p2 = 0;

 

for($i=0;$i<substr_count($text, "<NUMBERLIST>"); $i++){

$p1 = strpos($text, "<NUMBERLIST>", $p2);

$p2 = strpos($text, "NUMBERLIST>", $p1+12);

 

$list = substr($text, $p1, $p2 - $p1);

 

 

if(ereg("NUMBERLIST", $list)){

$list = explode("\n", $list);

 

//print_r($list);

 

for($x=0;$x<count($list);$x++){

if($list[$x] && !ereg("<",$list[$x])) {

$list[$x] = "<li>".$list[$x]."</li>";

}

}

 

$list = implode("", $list);

 

$text = substr_replace($text, $list, $p1, $p2 - $p1);

}

}

 

$text = ereg_replace("<NUMBERLIST>", "<OL class=\"number\">", $text);

$text = ereg_replace("</NUMBERLIST>", "</OL>", $text);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.