I am developing a script to format the data :
Change them if needed (your doctor will help you with this):{1:Your chair|Your pillow|{I:Your chair 1|Your pillow 2|Your mattress 3|Your shoes 4}|Your shoes} and i want everything inside {} to be as new list with the type stated inside braces {a: }
prefered seperator is |
PHP Code :
function processforsublist($str)
{
$start = strpos($str, '{');
$format = substr($str, $start+1 , 1);
$end = strpos($str, '}');
if($start!==false && $end!==false)
{
$cut = substr($str, $start, ($end-$start)+1);
$class = '';
switch ($format) {
case '1':
$class = 'list_number';
break;
case 'a':
$class = 'list_alpha_small';
break;
case 'A':
$class = 'list_alpha_caps';
break;
case 'i':
$class = 'list_roman_small';
break;
case 'I':
$class = 'list_roman_caps';
break;
default:
$class = 'list_number';
break;
}
$cutn = str_replace('{', '', $cut);
$cutn = str_replace('}', '', $cutn);
$cutn = str_replace($format.":", '', $cutn);
//echo $cutn;
$exploded = explode('|', $cutn);
$lis = '';
foreach ($exploded as $value) {
if(strpos($str, '{')!==false)
$lis .= "<li>".processforsublist($value)."</li>";
else
$lis .= "<li>".trim($value)."</li>";
}
$newstr = "<ol class='$class'>$lis</ol>";
echo $str."<hr/>".$cut."<hr/>".$newstr."<hr/>";
$istr = str_replace($cut, $newstr, $str);
return $istr;
}
else {
return $str;
}
}
echo processforsublist('Change them if needed (your doctor will help you with this):{1:Your chair|Your pillow|{I:Your chair 1|Your pillow 2|Your mattress 3|Your shoes 4}|Your shoes}');
Current Output :
Change them if needed (your doctor will help you with this):
1.Your chair
2.Your pillow
3.Your chair 1
4.Your pillow 2
5.Your mattress 3
6.Your shoes 4
|Your shoes}
Required Output:
Change them if needed (your doctor will help you with this):
1.Your chair
2.Your pillow
I.Your chair 1
II.Your pillow 2
III.Your mattress 3
IV.Your shoes 4
3.Your shoes