- Home
- Przykłady i porady PHP79
- Inne pomoce, software6
- Banery
- Hyde Park Private Zone6
- Polityka cookies
- Udostępnianie tekstów
© 2001 - 2024 PhpCodex
Jak utworzyć listy <ul> <ol> z list tekstowych * -
Przykład PHP2014-03-07 stopień trudności: łatwy<?
$text = "
* linia 1/1
* linia 1/2
* linia 1/3
- linia 2/1
- linia 2/2
- linia 2/3
";
//zamieniamy liste *
$text = preg_replace("/\*+(.*)?/i","<ul><li>$1</li></ul>",$text);
$text = preg_replace("/(\<\/ul\>\n(.*)\<ul\>*)+/","",$text);
//zamieniamy liste -
$text = preg_replace("/\-+(.*)?/i","<ol><li>$1</li></ol>",$text);
$text = preg_replace("/(\<\/ol\>\n(.*)\<ol\>*)+/","",$text);
echo $text;
?>
manual: preg_replace()