Search code examples
phpspecial-charactersprintf

Left pad a string with tabs using sprintf


I know that sprintf() allows to format string. How can I insert special character(tab in my case)?

10 tab chars("\t") after that symbol s.

Like this:

sprintf("%'\t's","str") = "*morespices*str"

This work::

sprintf("%'a10s","str") = "aaaaaaastr"
sprintf("%' 10s","str") = "       str"

Solution

  • This works fine for me:

    <?php
      echo sprintf("f%'\t10sf", 'str');
    

    Result:

    f                           strf