For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > March 2004 > Re: [SMARTY] Padding Strings









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] Padding Strings
David Förster

2004-03-19, 1:29 pm

> 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
Jake Stride

2004-03-19, 1:29 pm

Sorry, 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

David Förster

2004-03-19, 1:29 pm

On 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
Messju Mohr

2004-03-19, 1:29 pm

On 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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com