Talha Habib
Talha Habib

Reputation: 332

PHP split a string containing two words

Like "Multi thinker" its a string... in php how i can split it that multi shows in left and thinker shows in right like

MULTI                                                                                                                       Thinker

i will create a user input name whatever he input 'full name' will split like above.

here is the code i try

    <?php

      $name = $_POST['name'];

     echo str_replace(" ","\t \t",$name);
   ?>

here i used str_replace i already tried preg and ereg replace but it doesnt meet my requirement.

Upvotes: 1

Views: 922

Answers (1)

Tigger
Tigger

Reputation: 9130

Try something like this:

$name = 'Multi thinker';
$data = explode(' ',$name);
echo '<div>
      <div style="float:left">'.$data[0].'</div>
      <div style="float:right">'.$data[1].'</div>
      </div>';

Upvotes: 1

Related Questions