Connecting Tech Pros Worldwide Forums | Help | Site Map

Multiplicate a word..?

Newbie
 
Join Date: Dec 2008
Posts: 27
#1: Jun 13 '09
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

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,947
#2: Jun 13 '09

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.
n8kindt's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Southern California
Posts: 221
#3: Jun 13 '09

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.  
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,947
#4: Jun 13 '09

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.
n8kindt's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Southern California
Posts: 221
#5: Jun 13 '09

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
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,947
#6: Jun 13 '09

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