Jump to content

Convert a long sentence into words/string


t_k_eoh

Recommended Posts

Hi all,

Sorry for my previous posting but I would like to know how to convert a sentence into strings

 

Eg. "I am just a beginner in this PHP" into new lines as follows

 

I

am

just

a

beginner

in

this

PHP

 

Pls help. Thanks a lot!

 

 

Link to comment
Share on other sites

<?php

$word="I am just a beginner in this PHP";

$x=explode(' ',$word);

print_r($x);

?>

 

 

<?php

$word="I am just a beginner in this PHP";

$x=explode(' ',$word);

$word1=$x[0];
$word2=$x[1];
$word3=$x[2];
$word4=$x[3];
$word5=$x[4];
$word6=$x[5];
$word7=$x[6];
$word8=$x[7];

echo $word2;
?>

Link to comment
Share on other sites


<?php

$word="I am just a beginner in this PHP";

$x=explode(' ',$word);
$word = "";

$word.=$x[0]."<br>";
$word.=$x[1]."<br>";
$word.=$x[2]."<br>";
$word.=$x[3]."<br>";
$word.=$x[4]."<br>";
$word.=$x[5]."<br>";
$word.=$x[6]."<br>";
$word.=$x[7]."<br>";

echo $word;
?>

 

Huh ..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.