eo92866 Posted February 1, 2011 Share Posted February 1, 2011 hope to input the below data via $_POST into a while loop to preg_split by comma and then recursively create xml element tag with the various firstName lastName's and even separate further aliasFirstName aliasLastName's into an attribute field NAMES: firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName] $xml .= ' <element1 attribute="' . $_POST('AGE') . '">'; while ($row = ' . $_POST('NAMES') . ') { $row = preg_split('/[\s]*[,][\s]*/',' . $_POST["Actors"] . ',PREG_SPLIT_OFFSET_CAPTURE); $xml .= ' <element2> <NAME names="' . $_POST('NAMES') . '" alias="' . $_POST('NAMES') . '"></NAME> $xml .= ''; Quote Link to comment https://forums.phpfreaks.com/topic/226374-help-outputting-xml-from-php-_post-in-a-loop-and-preg_split/ Share on other sites More sharing options...
AbraCadaver Posted February 1, 2011 Share Posted February 1, 2011 hope to input the below data via $_POST into a while loop to preg_split by comma and then recursively create xml element tag with the various firstName lastName's and even separate further aliasFirstName aliasLastName's into an attribute field NAMES: firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName] O.K. great. Quote Link to comment https://forums.phpfreaks.com/topic/226374-help-outputting-xml-from-php-_post-in-a-loop-and-preg_split/#findComment-1168433 Share on other sites More sharing options...
Maq Posted February 1, 2011 Share Posted February 1, 2011 You haven't asked a question. We need more information. Quote Link to comment https://forums.phpfreaks.com/topic/226374-help-outputting-xml-from-php-_post-in-a-loop-and-preg_split/#findComment-1168443 Share on other sites More sharing options...
eo92866 Posted February 1, 2011 Author Share Posted February 1, 2011 ok... so, i would like some assistance in figuring a way to make a recursive output of $_POST in a loop for a single element and split that data from the array. hope that helsp??? Quote Link to comment https://forums.phpfreaks.com/topic/226374-help-outputting-xml-from-php-_post-in-a-loop-and-preg_split/#findComment-1168480 Share on other sites More sharing options...
eo92866 Posted February 1, 2011 Author Share Posted February 1, 2011 and there was a typo... just posting again for clarification NAMES: firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName], firstName lastName [aliasFirstName aliasLastName] $xml .= ' <element1 attribute="' . $_POST('AGE') . '">'; while ($row = ' . $_POST('NAMES') . ') { $row = preg_split('/[\s,]/',' . $_POST["NAMES"] . ',PREG_SPLIT_OFFSET_CAPTURE); $xml .= ' <element2> <NAME names="' . $_POST('NAMES') . '" alias="' . $_POST('NAMES') . '"></NAME> $xml .= ''; echo $xml; Quote Link to comment https://forums.phpfreaks.com/topic/226374-help-outputting-xml-from-php-_post-in-a-loop-and-preg_split/#findComment-1168510 Share on other sites More sharing options...
eo92866 Posted February 1, 2011 Author Share Posted February 1, 2011 so i changed the code around and i'm not getting the desired output if someone can please assist. 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. NAMES: firstName1 lastName1 [aliasFirstName1 aliasLastName1], firstName2 lastName2 [aliasFirstName2 aliasLastName2], firstName3 lastName3 [aliasFirstName3 aliasLastName3], firstName4 lastName4 [aliasFirstName4 aliasLastName4], etc. $xmlBody .= ' <division version=' . $_POST['group'] . '></division>'; $postData = $_POST["names"]; preg_match_all("/[a-zA-Z]* [[a-zA-Z]]*/",$postData,$matches); foreach ($matches as $data) $xmlBody .= ' <people> <names name=" . $data[0] . " display=" . $data[0] . ">. $data[0] .</names> </people>'; $xmlBody .= ''; Quote Link to comment https://forums.phpfreaks.com/topic/226374-help-outputting-xml-from-php-_post-in-a-loop-and-preg_split/#findComment-1168612 Share on other sites More sharing options...
eo92866 Posted February 2, 2011 Author Share Posted February 2, 2011 so i figured out how to separate the data by regular expressions $str = $_POST["mytaginfo"]; $mores = explode("], ",$str); foreach ($mores as $more) { $datas = explode(" [",$more); for ($tag=0; $tag=$datas; $tag++) { echo "<tag name='$tag[0]' display='$tag[1]'>$tag[0]</tag>"; } } what i am stuck on now and trying to figure out is... iterating the rest of the array into the echo statement, so i can display the rest of the array information incrementally. assistance would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/226374-help-outputting-xml-from-php-_post-in-a-loop-and-preg_split/#findComment-1169097 Share on other sites More sharing options...
eo92866 Posted February 4, 2011 Author Share Posted February 4, 2011 sorry for posting so late... figured it out... hope it helps someone just change the [ or , or intentionally left space for desired effect within the quotes " " $xmlBody .= ' //xml information here //xml tags here //end an xml tag </endTag>'; $str = $_POST["mytaginfo"]; //splits a pattern defined from mytaginfo by bracket comma and space $mores = explode("], ",$str); foreach ($mores as $more) { //splits a pattern defined from mytaginfo and into $more by space and bracket $datas = explode(" [" [" $more); //will place <tag attributes></tag> recursively as much as there is info within the $_POST mytaginfo array //[0] is the first starting spot of the array and so on $xmlBody .= "<tag name='$tag[0]' display='$tag[1]'>$tag[0]</tag>"; } //start xml again $xmlBody .= ' //more xml information //end xml <endTag>'; $xmlBody .= ""; echo $xmlBody; Quote Link to comment https://forums.phpfreaks.com/topic/226374-help-outputting-xml-from-php-_post-in-a-loop-and-preg_split/#findComment-1169644 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.