Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

explode function help

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
Hi, i have this code to split some text using the explode function
Code:
<?php
$cmd = $_POST['theCmd'];
$bs = $_POST['beenSub'];

if($bs == "yes"){
	$doCmd = explode(" ", $cmd);
	$command = "Command used: " . $doCmd[0] . " " .$doCmd[1]. " Reason: " . $doCmd[2];
}
?>
Code:
<form name="CLI" action="index.php" method="post"> 
<input name="theCmd" type="text" id="theCmd" size="100%"> 
<input type="hidden" name="beenSub" value="yes"> 
</form>
However, it only pics up the first word, how do i make it pick up all the words after the first command??

e.g. type admin_closesite 1 "reason here"

it picks up the admin_closesite 1 but it would only pick up the word reason, not reason here?

How do i make it pick all words after inside the ""'s??

any ideas??


Regards,

Martin

Computing Help And Info:
 
That would probably be because explode() doesn't pay any attention to the quote-context of the string. If you do:

print_r ($doCmd);

You'll probably see that the array has four elements, not three, because explode() is splitting the string at the space inside the quotes.

Try experimenting with the limit input parameter of explode(). I think

$doCmd = explode(" ", $cmd, [red]3[/red]);

might get you closer to what you want


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top