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

String alle x Zeichen mit Leerzeichen trennen

 
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
t91
Smarty Rookie


Joined: 10 Aug 2010
Posts: 7

PostPosted: Fri Sep 19, 2014 5:55 pm    Post subject: String alle x Zeichen mit Leerzeichen trennen Reply with quote

Gibt es eine Möglichkeit in Smarty einen String alle X Zeichen mit einem Leerzeichen zu trennen? Als Beispiel:

String 1234567890
Alle 3 Zeichen trennen
Ausgabe 123 456 789 0

Danke vorab.
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Mon Sep 22, 2014 8:37 am    Post subject: Reply with quote

Wäre mir nicht bekannt. Auch in PHP nicht. Entweder du machst dir ein Smarty PlugIn (je nachdem wie oft du es verwenden willst) oder du machst dann in dem template wo du es brauchst den "Smarty Code abschnitt".

Im Prinzip müsstest du eine Schleife machen, die (in deinem Fall) bei $i = 3 anfängt und dann über die Zeichenkette durchiteriert und den 3. Buchstaben durch 3. Buchstabe + Leerzeichen ersetzt (die neue Zeichenkette dann aber in eine zwischenvariable speichern, sonst bekommst du probleme mit deinem eigentlichen string). Beim nächsten Durchlauf der Schleife wird $i = $i+3 hochgezählt. Und Endbedingung ist eben $i < längeDerZeichenkette
Back to top
View user's profile Send private message Visit poster's website
t91
Smarty Rookie


Joined: 10 Aug 2010
Posts: 7

PostPosted: Mon Sep 22, 2014 8:43 am    Post subject: Reply with quote

Die Lösung war chunk_split

Code:


<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty wordwrap modifier plugin
 *
 * Type:     modifier<br>
 * Name:     chunk_split<br>
 * Purpose:  split it a string at certain intervals
 * @param string
 * @param integer
 * @param string
 * @return string
 */
function smarty_modifier_chunk_split($string,$length=76,$break="\r\n")
{
    return chunk_split($string,$length,$break);
}

?>

Back to top
View user's profile Send private message
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