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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eo92866
Forum Newbie
Posts: 2
Joined: Thu Dec 02, 2010 7:25 pm

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

Post 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 .= '';

Post Reply