Autor |
Beitrag |
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Mo 01.09.08 13:25
Hallo,
mal ne Frage an die Web-Programmierer:
Es gibt ja BBCodes wie Quote, Size etc. Die einen Parameter haben (können)
Nun haben Boards ja die Kontrolle, ob es gleich viele öffnende, wie schließende Tags gibt, das ist auch nicht das Problem...
Mein Problem ist eher: Wie kriege ich die entsprechenden Codes nach HTML geparst?
Weil ich ja zuerstmal den [size= in den entsprechenden Code ändere, dann hab ich aber das Problem, was ich mit dem ] am ende anfangen soll... dazwischen steht die Zahl, aber die kann ja beliebig sein...
Kann mir da jemand nen Tipp geben?
einfach alle [ in < und alle ] in > zu ändern führt ja zu Problemen, wenn man nen Fehler bei den Tags hat...
Danke im Vorraus,
Wolle
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
Yogu
Beiträge: 2598
Erhaltene Danke: 156
Ubuntu 13.04, Win 7
C# (VS 2013)
|
Verfasst: Mo 01.09.08 14:29
Google mal nach BBCODE PARSER PHP. Das erste Ergebnis sieht recht vielversprechend aus: BBCode-Parserklasse für PHP
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Mo 01.09.08 15:10
Okay, ich baus mal ein gucke wies wird...
@Irgendwer ders hier weiß: Wie läuft das denn hier im Forum?
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Mo 01.09.08 18:07
irgendwie versteh ich die callback-funktionen nicht wirklich...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
j.klugmann
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Mo 01.09.08 18:10
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Mo 01.09.08 18:30
was callback-funktionen sind, das weiß ich, nur nicht, wie die bei dem Parser aufgebaut sein müssen...
Bin halt mal wieder etwas zu doof
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
Yogu
Beiträge: 2598
Erhaltene Danke: 156
Ubuntu 13.04, Win 7
C# (VS 2013)
|
Verfasst: Mo 01.09.08 20:57
Wolle92 hat folgendes geschrieben: | Wie läuft das denn hier im Forum? |
Wie die erste Footer-Zeile verkündet:
Entwickler-Ecke.de 3.1.5 based on phpBB
Du kannst dir natürlich auch phpBB anschauen, aber das sind sehr, sehr viele Dateien. Bis du da den Teil gefunden hast, der den BBCode parst, ist einige Zeit verstrichen. Vor allem, weil phpBB3 auch noch benutzerdefinierte Tags unterstützt.
|
|
Wolle92
Beiträge: 1296
Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
|
Verfasst: Mo 01.09.08 21:03
Hm, ok, lassen wir das mit hier...
_________________ 1405006117752879898543142606244511569936384000000000.
|
|
BenBE
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Fr 05.09.08 13:00
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
DarkHunter
Beiträge: 477
Win XP
D3 Prof, D2005 PE
|
Verfasst: Di 09.09.08 09:03
RegExe sind ein ein ungeheuer mächtige Werkzeug um das zu bewerkstelligen.
Also angenommen, es geht um das tag
Quelltext 1:
| <span style="font-size: 6px; line-height: normal">Ein Text in Schriftgröße 6</span> |
Dann wäre ein passendere Regex um das Ding zu finden:
Quelltext 1:
| \[size=(\d*)\](.*)\[\/size\] |
das ganze in die funktion preg_replace() gepackt und schon werden alle [size]-Tags in <span style="font-size:6pt">Ein Text in Schriftgröße 6</span> umgewandelt
Quelltext 1: 2: 3: 4: 5:
| $text = preg_replace( '/\[size=(\d*)\](.*)\[\/size\]/i', '<span style="font-size:\\1pt>\\2</span>', $text ); |
Das kann man dann natürlich beliebig für andere Tags wiederholen. Streckt den Code zwar ein wenig, aber es erfüllt seinen Zweck.
Zum Verständnis von RegExen empfehle ich diese Seite
_________________ I believe that every human has a finite number of heart-beats. I don't intend to waste any of mine running around doing exercises.
- Neil Armstrong
|
|
BenBE
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Di 09.09.08 12:25
Wobei phpBB hier noch (?R) nutzt, d.h. Rekursiv matcht, um bei verschachtelten Regechsen das richtige Ende zu finden ...
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|