PHP, Cutting String
<p>I have this 
string(245) "- Current Map = VILLA - Current Missions = VEGAS JUNKYARD, VILLA, PRESIDIO, KILL HOUSE, STREETS, THREE KINGDOMS CASINO; - Available Missions = TRAINYARD, IMPORT/EXPORT, MURDERTOWN, CQB TRAINING, OIL REFINERY, CONVENTION CENTER, THEATER;"</p>

<p>Current Map is always one value,
Current Missions and Availible Missions have a variable amount of values.</p>

<hr>

<p>I would like to parse the string so that I have an array that looks like this:</p>

<pre><code>Array ([Current Map] =&gt; VILLA [Current Missions] =&gt; Array ([0] =&gt; VEGAS JUNKYARD [1] =&gt; VILLA [2] =&gt; PRESIDIO [3] =&gt; KILL HOUSE [4] =&gt; STREETS [5] =&gt; THREE KINGDOMS CASINO)  [Availible Missions] =&gt; Array ([0] =&gt; TRAINYARD [1] =&gt; IMPORT/EXPORT [2] =&gt; MURDERTOWN [3]  =&gt; CQB TRAINING [4] =&gt; OIL REFINERY [5] =&gt; CONVENTION CENTER [6] =&gt; THEATER))
</code></pre>

<hr>

<p>What works: It seperates the 3 big parts (Current Map, Current Missions, Availible Missions)</p>

<p>What doesn't work: Seperating the multiple values of "Current Missions" and "Availible Missions" into an array.</p>

<p>Bug (or I'm just stupid):Notice the semicolon before "Availible Missions"</p>

<pre><code>$search_strs_maps = array('Current Map = ', '- Current Missions = ', '; - Available  Missions = ', ';');
</code></pre>

<p>If I put the semicolon there it doesnt find anything even though I'm pretty sure the semicolon is in the string.
<br></p>

<hr>

<p>Reason I'm putting this up is that I can' figure out why it doesnt find anything when I put the semicolon before "Availible Missions" and it's driving me crazy. Also I could use a second set of eyes on the code and some advice on how to make it nicer. Thanks for your help!</p>

<p>This is what I have written so far. </p>

<pre><code>&lt;?php
$str_map = '- Current Map = VILLA - Current Missions = VEGAS JUNKYARD, VILLA, PRESIDIO,  KILL HOUSE, STREETS, THREE KINGDOMS CASINO; - Available Missions = TRAINYARD, IMPORT/EXPORT, MURDERTOWN, CQB TRAINING, OIL REFINERY, CONVENTION CENTER, THEATER;';
$search_strs_maps = array('Current Map = ', '- Current Missions = ', '- Available  Missions = ', ';');
for ($i=0; $i&lt;3; $i++){

                $str_map = trim ($str_map);
                output($str_map, 'Complete String');
                //Cut of the beginning : "- Current Map = "
                $start_pos = str_pos_last ($str_map,  $search_strs_maps[$i]);
                output($start_pos, 'Starting position');
                $str_map = substr($str_map, $start_pos);
                output($str_map, 'String after first cut:');
                //Cut the remaining part to "Current Missions ="
                $end_pos = strpos ($str_map, $search_strs_maps[$i+1]);
                output($end_pos, 'End position');
                //Save the new string without for example "VILLA"
                $ergebnis = substr($str_map, 0, $end_pos);
                $ergebnis = trim ($ergebnis);
                output($ergebnis, 'Finished result');
                $str_map = substr($str_map, $end_pos);
                echo '&lt;hr&gt;';
                if ($i==0){
                    $arr_return_strs['current_map'] = $ergebnis;
                }else{  //arrays
                    //stupid semicolon that doesnt get cut of
                    $ergebnis = str_replace ($str_map, ';', '');
                    $arr_maps_temp = array();
                    //count the number of commas, if there is one comma that means there are 2 words, there is no comma at the end
                    $map_count = substr_count ($ergebnis, ',')+1;
                    for ($ii=0;$ii&lt;$map_count;$ii++){
                        echo '&lt;hr';
                        //cut at first comma
                        $result_pos = strpos($str_map, ',');
                        //save
                        $result_map = substr($str_map, 0, $result_pos);
                        //cut of the result+comma
                        $ergebnis = substr ($ergebnis, $result_pos);
                        output($result_map, 'Result is:');
                    }
                }

            }
    echo '&lt;hr&gt;&lt;hr&gt;&lt;hr&gt;';
    print_r ($arr_return_strs);

function str_pos_last ($input_str, $search_str, $offset=0){
    //this function returns the endposition of a string we search for, strpos returns the beginning...
    $str_begin = strpos ($input_str, $search_str);
    $str_end = $str_begin + strlen($search_str);
    return $str_end;
}

function output ($var, $desc){
echo $desc.'&lt;br&gt;';
var_dump ($var);
echo '&lt;hr&gt;';
}
?&gt;
</code></pre>
