PHP:复制一个句子并将它们保存到用空格分隔的不同变量中[关闭]

I'm new here and I would like to ask two questions. Feel free to close this thread if this has been answered before and please put a link on it so that I can continue there instead. Thanks.

Now for my question... It's basically it in the title but if it wasn't clear enough for you guys. Let me expound it more.

Lets say I inputted the words "Hi there, my name is Kikert!" (Without the qoutes) and i would like to save each and every word into a different variable separated by a space.

Example:
Hi = saved in var1
there, = saved in var2
my = var3
etc.

or something like that.

And I would like to output lets say "there, Kikert! name my"

Is it possible? And if it is, where do I start to learn the code? What logic should i follow for this. It's quite confusing for me. The code is in PHP (I dont know if PHP versions can affect or any other HTML versions)

This is the second question:
The purpose for this question is a translator.Example: I will input printf("blah blah blah"); in a text box then it will output system.out.println("blah blah blah");

How can I just change the "printf" to "system.out.println" while the insides and the parenthesis remains untouched? This is also coded PHP. Basically if the program detects the word printf then it will change it to system.out.println in the output. Like a string changer or somekind.

EDIT:
For clarifications: The code is written in PHP and I was assigned to do a C to JAVA converter in PHP.

$text = "here is a sample: this text, and this will be exploded. this also | this one too :)";
$exploded = multiexplode(array(",",".","|",":"),$text);

print_r($exploded);

now $exploded contains all the words as an array

$var1 = $exploded[0]; $var2 = $exploded[1]; $var3 = $exploded[2];

but there is no point of assigning it to each variable.. better use arrays

for converting you can try str_replace http://us2.php.net/manual/en/function.str-replace.php

There are a couple of ways to handle something like this. Probably the easiest way is just to explode the string into an array at the space.

$string = 'Hi there, my name is Kikert!';

$chunks = explode(' ', $string);

print "<pre>"; print_r($chunks);  print "</pre>";

This will give you each word as a separate item in $chunks. You can reference each item by using its position in the array. For instance, if you wanted to print the third item in the array, you could use:

print $chunks[2];  // OUTPUTS 'my'

Then you can rearrange them to your heart's content.

For the second part of your question, I'm not sure I fully understand what you are asking, but if you are wondering how to do a find/replace, you can do it like this:

preg_replace('/printf\s?\(/', 'system.out.println(', $string);

I think the explode() function is what you may be looking for:

$strSentence = "Hi there, my name is Kikert!";
$arrSentence = explode(" ", $strSentence);

// Access each word using $arrSentence[$key]
// E.g. echo $arrSentence[0]." ".$arrSentence[1]; // Output: Hi there,

It's also worth having a look at the preg_split() function.