Code Comments
Programming Forum and web based access to our favorite programming groups.> What is the easiest way to pad a string in smarty?
Just embed the smarty-var in the string:
--{$myVar}--
works also in loops ;)
- david
Post Follow-up to this messageSorry, I didn't explain it well enough, because I don't know what the strin=
g
will be as it comes from a db, so it could be:
---ab---
I basically want to pad a string left and right, but dynamically, ie the
same as:
<?php
$input =3D "Alien";
echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
?>
Jake
On 13/3/04 9:37, "David F=F6rster" <david@dfoerster.de> wrote:
>=20
> Just embed the smarty-var in the string:
> --{$myVar}--
>=20
> works also in loops ;)
>=20
> - david
Post Follow-up to this messageOn Sat, 13 Mar 2004 10:00:46 +0000 Jake Stride <jas@dcs.warwick.ac.uk> wrote: > Sorry, I didn't explain it well enough, because I don't know what the > string will be as it comes from a db, so it could be: > > ---ab--- > > I basically want to pad a string left and right, but dynamically, ie > the same as: > > <?php > $input = "Alien"; > echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___" > ?> If you're security settings are not too strict, you can use any php function as a modifier, so & #123;$myVar|str_pad:10:'_':STR_PAD_BOTH} should work. - david
Post Follow-up to this messageOn Sat, Mar 13, 2004 at 12:16:28PM +0200, David Förster wrote:
> On Sat, 13 Mar 2004 10:00:46 +0000
> Jake Stride <jas@dcs.warwick.ac.uk> wrote:
>
>
> If you're security settings are not too strict, you can use any php
> function as a modifier, so
> & #123;$myVar|str_pad:10:'_':STR_PAD_BOTH}
(just a little addition)
to get the const straight it's:
{$myVar|str_pad:10:'_':$smarty.const.STR_PAD_BOTH}
greetings
messju
> should work.
>
> - david
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.