Multiplicate a word..?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pheddy
    New Member
    • Dec 2008
    • 80

    #1

    Multiplicate a word..?

    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?

    Code:
    $VarT * (" ")
    Thanks for all the support!
    Frederik
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by Pheddy
    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?

    Code:
    $VarT * (" ")
    Thanks for all the support!
    Frederik
    Maybe the str_pad() function can help you.

    Comment

    • n8kindt
      New Member
      • Mar 2008
      • 221

      #3
      Originally posted by Pheddy
      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?

      Code:
      $VarT * (" ")
      Thanks for all the support!
      Frederik

      i think this is what u're looking for

      Code:
      for($i=0;$i<$VarT;$i++){
       echo '&nbsp';
      }

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by n8kindt
        i think this is what u're looking for

        Code:
        for($i=0;$i<$VarT;$i++){
         echo '&nbsp';
        }
        str_pad() does it for you.

        Comment

        • n8kindt
          New Member
          • Mar 2008
          • 221

          #5
          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

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by n8kindt
            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.

            Comment

            Working...