0

i have this string datatype:

$mystring = "['def step1(self):\n\ttry:\n\t\tglobal testcaseResult\n\t\tassert self.Remedy.returnStatus\n\t\tassert self.Remedy.returnStatus\n\t\tprint(self.Remedy.returnMessage)\n\t self.MOSS IOS.element_wait_by_xpath_hide(self, mossDriver, action_msg, by_xpath, timeout=5)\n\t self.Remedy.ResolutionCatPopulation(self, driver, ResoCat1, ResoCat2, ResoCat3=None)\n@def step2(self):\n\tself.MOSS IOS.element_wait_by_xpath_get_text(self, mossDriver, action_msg, by_xpath, timeout=30)\n@def step3(self):\n\tself.MOSS IOS.element_wait_by_xpath_get_text(self, mossDriver, action_msg, by_xpath, timeout=30)\n']"

how do i make it store in an become associative array(My Goal):

$newAssociativeArray= array("def step1(self)"=>"\n\ttry:\n\t\tglobal testcaseResult\n\t\tassert self.Remedy.returnStatus\n\t\tassert self.Remedy.returnStatus\n\t\tprint(self.Remedy.returnMessage)\n\t self.MOSS IOS.element_wait_by_xpath_hide(self, mossDriver, action_msg, by_xpath, timeout=5)\n\t self.Remedy.ResolutionCatPopulation(self, driver, ResoCat1, ResoCat2, ResoCat3=None)\n", "def step2(self)"=>"\n\tself.MOSS IOS.element_wait_by_xpath_get_text(self, mossDriver, action_msg, by_xpath, timeout=30)\n", "def step3(self)"=>"\n\tself.MOSS IOS.element_wait_by_xpath_get_text(self, mossDriver, action_msg, by_xpath, timeout=30)\n");

what i did:

$explodearray = explode("@",$mystring);
$newAssociativeArray[$key] = array();
for($countnum = 0; $countnum<count($explodearray);$countnum++){

if (strpos($explodearray[$countnum],"def") !== FALSE) { 
    echo "Match found"; 
  $newAssociativeArray[$key]  = $explodearray[$countnum];
}
else{
    $newAssociativeArray[$key][] = $explodearray[$countnum];
}


}

print_r( $newAssociativeArray);

1 Answer 1

1

more or less like this .. '[\'def .. ']'));

<?php
            print_r( explode('\n\t','[\'def step1(self):\n\ttry:\n\t\tglobal testcaseResult\n\t\tassert self.Remedy.returnStatus\n\t\tassert self.Remedy.returnStatus\n\t\tprint(self.Remedy.returnMessage)\n\t self.MOSS IOS.element_wait_by_xpath_hide(self, mossDriver, action_msg, by_xpath, timeout=5)\n\t self.Remedy.ResolutionCatPopulation(self, driver, ResoCat1, ResoCat2, ResoCat3=None)\n@def step2(self):\n\tself.MOSS IOS.element_wait_by_xpath_get_text(self, mossDriver, action_msg, by_xpath, timeout=30)\n@def step3(self):\n\tself.MOSS IOS.element_wait_by_xpath_get_text(self, mossDriver, action_msg, by_xpath, timeout=30)\n\']'));
    ?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.