|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
T. Smarty Regular
Joined: 22 Aug 2004 Posts: 69 Location: AT
|
Posted: Mon Feb 14, 2005 8:20 pm Post subject: preg_replace/ereg_replace in smarty ;) |
|
|
Guten Abend!
Ich dachte mir, ich probier heut mal was lustiges in Smarty aus und zwar: jeder kennts aus diversen Foren man schreibt ein [quote=sepp]bla[/quote]
und hätt dann gerne:
<strong>sepp schrieb</strong>
<div class="irgendeine">bla</div>
denk ich mir, klar schreib ich mir mal die regex funktion dafür (bzw. google war mein freund) - kommt dabei raus:
$var = preg_replace("/\[quote=(.*)\](.*)\[\/quote\]/is","<strong>\\1 schrieb:</strong><div>\\2</div>",$var);
$var = preg_replace("/\[quote](.*)\[\/quote\]/is","<strong>Zitat:</strong><div>\\1</div>",$var);
(also einmal für Zitat von und einmal ohne)
Jetzt denk ich mir, das bau ich gleich in smarty ein und schrieb folgendes:
{$Posts[count].Beitrag|preg_replace:"/\[quote](.*)\[\/quote\]/is":"<strong>Zitat:</strong><div style=\"border:1px solid;padding:5px\">\\1</div>"}
nur hau das so nicht hin, entweder es tut gar nix oder ich spiel mich solang mit den Slashes bis es funkt.
Natürlich kann ich das ganze direkt in PHP machen. Aber nachdem das irgendwie doch mehr was mit der Anzeige zu tun hat als mit Code (alles relativ natürlich) wollt ich es in Smarty probieren, va. wegen dem <div> und dem ganzen kram der da noch reinkommt (wechselnde hintergrundfarben mit cycle oder so).
Ich hab zwar schon in der Suche gelesen das mans lieber mit PHP machen soll, aber falls es eine brauchbare Lösung gäge würde mich die doch sehr interessieren
mfg Thomas _________________ Oppossom - Heavy rock from austria |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Feb 14, 2005 8:32 pm Post subject: |
|
|
die reihenfolge der parameter ist nicht korrekt.
preg_replace will als erstes die expression, du gibst als ersten den zu modifizierenden string.
du möchtest smarty.php.net/regex_replace nehmen.
noch viel lieber möchtest du das ganze in einem eigenen modifier kapseln und nicht im template machen. |
|
Back to top |
|
T. Smarty Regular
Joined: 22 Aug 2004 Posts: 69 Location: AT
|
Posted: Tue Feb 15, 2005 10:36 am Post subject: |
|
|
Herzlichen Dank, werd ich dann gleich testen.
Aber ich wusste gar nicht, was ich alles möchte
mfg Thomas _________________ Oppossom - Heavy rock from austria |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Feb 15, 2005 10:47 am Post subject: |
|
|
T. wrote: | Aber ich wusste gar nicht, was ich alles möchte |
is aber so |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|