Jump to content

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


eo92866

Recommended Posts

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

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.

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;

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

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.

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.