Add whitespace between letters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lagon666
    New Member
    • Jun 2009
    • 22

    Add whitespace between letters

    Does PHP has a function to add whitespace between letters?

    Convert this "abc" to "a b c"?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Not as specific function, no (at least as far as I can tell), but you can easily achieve this by just looping through the string and adding a space after each letter.

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      You could use
      preg_replace("/(.)/i", "\${1} ", $str);

      it should find each character, and replace each with a character plus space. You can then truncate the last space if you want.

      edited..
      made a slight correction.

      Comment

      • Lagon666
        New Member
        • Jun 2009
        • 22

        #4
        Thanks
        preg_split("//", $text) works too. But it might be slow.

        Comment

        • zorgi
          Recognized Expert Contributor
          • Mar 2008
          • 431

          #5
          maybe this:

          echo wordwrap("abc", 1, " ", true);

          Comment

          Working...