title: PHP Centering strings with printf()
body: <h1>Q: How to center a string using <code>printf</code> ??</h1>
  
  <p>I know how to align left and right using <code>printf</code> func, as follows,</p>
  
  <pre class="lang-php prettyprint-override"><code>$str = '-DaTa-';
  printf(''%-50s'', $str); #leftAlign / PadRight
  printf(''%50s'', $str);  #RightAlign/ PadLeft
  </code></pre>
  
  <blockquote>
    <p>Output,</p>
  
  <pre><code>'-DaTa-                                            '
  '                                            -DaTa-'
  </code></pre>
  </blockquote>
  
  <p>But, How am i gonna center the String like this,</p>
  
  <pre><code>'                      -DaTa-                      '
  </code></pre>
  
  <p><br></p>
  
  <p>After Searching for this I found a few answers but non of them were written in <code>PHP</code>. So, I am having difficulty trying to understand them. So, I asked this question again focusing on <code>PHP</code>.</p>
  
  <blockquote>
    <p>EDIT:  I just wanted a answer that uses only <code>printf</code> func. because using <code>str_pad</code> is ok, But in case of a lot of data for centering in this form becomes ugly. AND, I already knew it was possible to achive using <code>str_pad</code>, thats why I taged the question with <code>printf</code>....</p>
  </blockquote>