Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:12:07+00:00 2026-06-12T21:12:07+00:00

I have this string(245) – Current Map = VILLA – Current Missions = VEGAS

  • 0

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;”

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


I would like to parse the string so that I have an array that looks like this:

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

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

What doesn’t work: Seperating the multiple values of “Current Missions” and “Availible Missions” into an array.

Bug (or I’m just stupid):Notice the semicolon before “Availible Missions”

$search_strs_maps = array('Current Map = ', '- Current Missions = ', '; - Available  Missions = ', ';');

If I put the semicolon there it doesnt find anything even though I’m pretty sure the semicolon is in the string.


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!

This is what I have written so far.

<?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<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 '<hr>';
                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<$map_count;$ii++){
                        echo '<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 '<hr><hr><hr>';
    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.'<br>';
var_dump ($var);
echo '<hr>';
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:12:08+00:00Added an answer on June 12, 2026 at 9:12 pm
    $initialString = "- 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;";
    
    
    $resultArray = array();
    $blockArray = explode('-',$initialString);
    foreach($blockArray as $setArray) {
        if (!empty($setArray)) {
            list($dataArrayKey, $dataArrayValues) = explode('=',$setArray);
            $dataArrayKey = trim($dataArrayKey);
            $dataArrayValues = trim($dataArrayValues,' ;');
            if ($dataArrayKey == 'Current Map') {
                $resultArray[$dataArrayKey] = trim($dataArrayValues);
            } else {
                $dataArrayValues = explode('=', $dataArrayValues);
                foreach($dataArrayValues as $dataArrayValue) {
                    $dataArrayEntries = explode(',',$dataArrayValue);
                    $resultArray[$dataArrayKey] = $dataArrayEntries;
                }
            }
        }
    }
    
    var_dump($resultArray);
    

    gives

    array
      'Current Map' => string 'VILLA' (length=5)
      'Current Missions' => 
        array
          0 => string 'VEGAS JUNKYARD' (length=14)
          1 => string ' VILLA' (length=6)
          2 => string ' PRESIDIO' (length=9)
          3 => string ' KILL HOUSE' (length=11)
          4 => string ' STREETS' (length=8)
          5 => string ' THREE KINGDOMS CASINO' (length=22)
      'Available Missions' => 
        array
          0 => string 'TRAINYARD' (length=9)
          1 => string ' IMPORT/EXPORT' (length=14)
          2 => string ' MURDERTOWN' (length=11)
          3 => string ' CQB TRAINING' (length=13)
          4 => string ' OIL REFINERY' (length=13)
          5 => string ' CONVENTION CENTER' (length=18)
          6 => string ' THEATER' (length=8)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have this String String criteria=ESS.(BVA4+BVA5)+(-(DIESE.(BVM5+BVM6))); I want to put validations on it. It
I have this string in php i want to skip the ppattern ------------------------------------------ FROM:Andy;
I have this string in R: numbers <- 4 4956 1.00e-09 50.9 1.244 47.1
I have this string: 123-456-7 I need to get this string: 1234567 How I
I have this string: \Blah \'Blah\' Blah\ . There is another string inside it.
I have this string stored in a variable: IN=bla@some.com;john@home.com Now I would like to
I have this string containing a large chunk of html and am trying to
I have this string aa b qqidjwljd p fjem I need to replace b
We have this string: according to posts #4,#5 and #6 the word... I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.