Potřebuji nahradit všechny \n (řádky) mezi [(.*?)] (tedy BB codem) a textem, kromě určitých tagů, jako je [url], a to ať ve formě [url][/url] nebo [url=...]...[/url].
Příklad
- Kód: Vybrat vše
[h1]Nadpis[/h1]
nějaký text
Aby to ten nový řádek dalo do pryč, ale ne všechny řádky. Jen ty, které jsou zakončeny BB codem. Výsledek by měl být:
- Kód: Vybrat vše
[h1]Nadpis[/h1]nějaký text
Pokud je ale ten řádek zakončen [/url], tak ovšem ne.
Cílem je docílit toho, že v celém textu odstraním odřádkování a ponechám ho jen tam, kde má opravdu být.
Ideálním řešením by bylo nahradit dvojité odřákování tak, aby se to dalo do odstavců <p></p>. Ovšem nevím jak na to, když budu mít třeba:
- Kód: Vybrat vše
[h1]Nadpis[/h1]
text
text
Za H1 nemá být <br>, tudíž se musí \n odstranit.
Zbylý text hodit do odstavců. Je třeba předpokládat, že v textu budou dále nadpisy nižší úrovně.
Dokáže to někdo? ... Já zkouším už několik dní a pořád to má nějaké vady.
- Kód: Vybrat vše
$text = preg_replace("/\[(.*?)\](\s+)\\n(\s+)\[(.*?)\]/s", ' [$1] [$4] ', $text);
$text = preg_replace("/\[(.*?)\](\s+)\\n(\s+)\[(.*?)\]/s", ' [$1] [$4] ', $text);
$text = preg_replace("/\[(.*?)\](\s+)\\n(\s+)\[(.*?)\]/s", ' [$1] [$4] ', $text);
$text = preg_replace("/\[(.*?)\](\s+)\[(.*?)\]/s", ' [$1] [$3] ', $text);
$text = preg_replace("/\[(.*?)\](\s+)\[(.*?)\]/s", ' [$1] [$3] ', $text);
$text = preg_replace("/\[(.*?)\](\s+)\[(.*?)\]/s", ' [$1] [$3] ', $text);
$text = preg_replace("/\[\/(.*?)\](\s+)\\n/", '[/$1]', $text);
$text = preg_replace("/\[h1\](.*?)\[\/h1\]/s", ' <h1>$1</h1> ', $text);
$text = preg_replace("/\[h2\](.*?)\[\/h2\]/s", ' <h2>$1</h2> ', $text);
$text = preg_replace("/\[h3\](.*?)\[\/h3\]/s", ' <h3>$1</h3> ', $text);
$text = preg_replace("/\[p\](.*?)\[\/p\]/s", ' <p>$1</p> ', $text);
$text = preg_replace("/\[b\](.*?)\[\/b\]/s", ' <strong>$1</strong> ', $text);
$text = str_replace("[br]", "<br>", $text);
$text = preg_replace("/\[table\](.*?)\[\/table\]/s", ' <table>$1</table> ', $text);
$text = preg_replace("/\[tr\](.*?)\[\/tr\]/s", ' <tr>$1</tr> ', $text);
$text = preg_replace("/\[td\](.*?)\[\/td\]/s", ' <td>$1</td> ', $text);
$text = preg_replace("/(<br>\s*)+(\n)*+(<br>)/s", ' <$4> ', $text);
$text = preg_replace("/\[url=(\W?)(.*?)(\W?)\](.*?)\[\/url\]/s", ' <a href="$2" target="_blank">$4</a> ', $text);
$text = preg_replace("/\\n/s", ' <br>
', $text);
return $text;
Prvních pár řádků se opakuje, protože ne vždy se to dokončí celé ... Chtělo by to nějaký repeater ...