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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.