Page 1 of 1

help outputting xml from php $_POST in a loop and preg_match

Posted: Tue Feb 01, 2011 6:23 pm
by eo92866
so i'm not getting the desired output... if someone can please assist... much appreciated.

what i want to happen, but not occurring is... to match firstName lastName's [aliasFirstName aliasLastName] and to be able to call the data out of the array to be recursively printed to within an xml element. the names are separated by commas, so my hope is to have firstName1 lastName1 be placed into name=" . $data[0] . " and aliasFirstName1 aliasLastName1 be placed into display=" . $data[0] . "

NAMES: firstName1 lastName1 [aliasFirstName1 aliasLastName1], firstName2 lastName2 [aliasFirstName2 aliasLastName2], firstName3 lastName3 [aliasFirstName3 aliasLastName3], firstName4 lastName4 [aliasFirstName4 aliasLastName4], etc.

Code: Select all

$xmlBody .= '
<division version=' . $_POST['group'] . '></division>';

$postData = $_POST["names"];
preg_match_all("/[a-zA-Z]* [[a-zA-Z]]*/",$postData,$matches);
//or can also use if the below is correct???
//preg_match_all("/ ^[\w i] [\w i] [[\w i \w i]]$ /",$postData,$matches);   

foreach ($matches as $data)

$xmlBody .= '
<people>
  <names name=" . $data[0] . " display=" . $data[0] . ">. $data[0] .</names>
</people>';
$xmlBody .= '';