Connecting Tech Pros Worldwide Help | Site Map

Multiplicate a word..?

  #1  
Old June 13th, 2009, 02:33 AM
Newbie
 
Join Date: Dec 2008
Posts: 27
Hi everyone!

I have created a script that finds the lenght difference between to text fields. Now I want to and the difference to the shortest text field. But Im in a little trouble multiplicate a space rather than numbers.. So my question is how do I duplicate a word multiple times?

Expand|Select|Wrap|Line Numbers
  1. $VarT * (" ")
Thanks for all the support!
Frederik
  #2  
Old June 13th, 2009, 02:58 AM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,862
Provided Answers: 9

re: Multiplicate a word..?


Quote:
Originally Posted by Pheddy View Post
Hi everyone!

I have created a script that finds the lenght difference between to text fields. Now I want to and the difference to the shortest text field. But Im in a little trouble multiplicate a space rather than numbers.. So my question is how do I duplicate a word multiple times?

Expand|Select|Wrap|Line Numbers
  1. $VarT * (" ")
Thanks for all the support!
Frederik
Maybe the str_pad() function can help you.
  #3  
Old June 13th, 2009, 08:46 PM
n8kindt's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Southern California
Posts: 221

re: Multiplicate a word..?


Quote:
Originally Posted by Pheddy View Post
Hi everyone!

I have created a script that finds the lenght difference between to text fields. Now I want to and the difference to the shortest text field. But Im in a little trouble multiplicate a space rather than numbers.. So my question is how do I duplicate a word multiple times?

Expand|Select|Wrap|Line Numbers
  1. $VarT * (" ")
Thanks for all the support!
Frederik

i think this is what u're looking for

Expand|Select|Wrap|Line Numbers
  1. for($i=0;$i<$VarT;$i++){
  2.  echo '&nbsp';
  3. }
  4.  
  #4  
Old June 13th, 2009, 09:19 PM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,862
Provided Answers: 9

re: Multiplicate a word..?


Quote:
Originally Posted by n8kindt View Post
i think this is what u're looking for

Expand|Select|Wrap|Line Numbers
  1. for($i=0;$i<$VarT;$i++){
  2.  echo '&nbsp';
  3. }
  4.  
str_pad() does it for you.
  #5  
Old June 13th, 2009, 09:23 PM
n8kindt's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Southern California
Posts: 221

re: Multiplicate a word..?


actually after looking at the str_pad function closer i think it would also work but i found an even more straightforward function: str_repeat
  #6  
Old June 13th, 2009, 09:31 PM
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,862
Provided Answers: 9

re: Multiplicate a word..?


Quote:
Originally Posted by n8kindt View Post
actually after looking at the str_pad function closer i think it would also work but i found an even more straightforward function: str_repeat
I'd still go with str_pad(). It's use was intended for this scenario. Afterall, we are 'padding' a string. No biggie.

Adding to why I think str_pad() would be better: str_repeat() is for repeating a string x amount of times. str_pad() is for adding a string to another string x amount of times.
Reply