Hi guys,
What I'm trying to do is read in plaintext with no formatting, for example it might be a string such as:
fleets
Large Cargo 5 Battleship 5
Solar Satellite 10
You see that there are multiple spaces between each item in cases. Basically, what I wish to do is store each of the numbers associated with each item into a variable, for example $lc, $bs and $sat. Here is my attempt so far at getting one of the numbers seperate:
if(preg_match("/Battleship\s*\d*/i", $string, $output))
{
// if the pattern matches we echo this
echo 'The string was found: ' . $output[0] . '<br>';
$bs = $output[0];
preg_match("/\d*/", $bs, $output);
//$bs = preg_replace("/\s*/","",$bs);
//$bs = explode(" ",$bs);
//print_r($bs);
echo 'Number of Battleships: ' . $output[0];
}
else
{
// if no match is found we echo this line
echo 'No match found';
}
Where $string is the text I put above.
When I first do the preg_match, I get
Battleship 5
As the output, which is what I expected, however the second output is blank, any dieas what Im missing out? The // commented lines are other attempts with various methods. Any help is greatly appreciated.