Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

preg_replace/ereg_replace in smarty ;)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
T.
Smarty Regular


Joined: 22 Aug 2004
Posts: 69
Location: AT

PostPosted: Mon Feb 14, 2005 8:20 pm    Post subject: preg_replace/ereg_replace in smarty ;) Reply with quote

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 Wink

mfg Thomas
_________________
Oppossom - Heavy rock from austria
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Feb 14, 2005 8:32 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
T.
Smarty Regular


Joined: 22 Aug 2004
Posts: 69
Location: AT

PostPosted: Tue Feb 15, 2005 10:36 am    Post subject: Reply with quote

Herzlichen Dank, werd ich dann gleich testen.

Aber ich wusste gar nicht, was ich alles möchte Wink

mfg Thomas
_________________
Oppossom - Heavy rock from austria
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Feb 15, 2005 10:47 am    Post subject: Reply with quote

T. wrote:
Aber ich wusste gar nicht, was ich alles möchte Wink


is aber so Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP