Jump to content

eo92866

Members
  • Posts

    40
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

eo92866's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. so this is what i ended up with and did to explode multiple words and then display them separately... and as an added bonus... the example also has a way to place php into the creation of your xml document. $xmlBody .= ' <position>' . $_POST["position"] . '</position>'; //input data assigned to $str $str = $_POST["mydata"]; //splitting $str with ]; and assigning to $mores $mores = explode("];",$str); //creating a loop foreach ($mores as $more) { //splitting data even further with [ and assigning to $datas $datas = explode("[",$more); //trimming array and assigning $datas sub 0 to $name $name = trim($datas[0],""); //trimming array and assigning $datas sub 1 to $nname and used only if needed #$nname = trim($datas[1],""); //split even further on space and assign to $fnameParts $fnameParts = explode(" ",$name); //assign $fnameParts sub 0 to $fname $fname = $fnameParts[0]; //assign $fnameParts sub 1 to $lname $lname = $fnameParts[1]; $xmlBody .= " <member name='$lname, $fname' display='$datas'>Name</member>"; } $xmlBody .= ""; echo $xmlBody; hope this helps someone down the line.
  2. currently, there are no middle names... and i'm hoping there are no surprise middle names down the line... but i guess i shouldn't discount the possibility of someone deciding to place middle names in there at some point. and yes, they are all in the format of firstName LastName [nickname] or as you put it: <member name='Cruise, Tom' display='Tom Cruise'>Name</member>
  3. hope this example of names helps $mydata = Tom Cruise [Tommy]; Hillary Duff [Hills]; Kate Hudson [Katie]; Dave Chappelle [Dave]; Bradley Pitt [brad]; Angelina Jollie [Angie] and the output is into an XML document $xmlBody .= ' <position>' . $_POST["position"] . '</position>'; $str = $_POST["mydata"]; $mores = explode("[];",$str); foreach ($mores as $more) { $datas = explode(" ",$more); if (array_values ($datas) === $datas) $xmlBody .= " <member name='$datas[1], $datas[0]' display='$datas[0] $datas[1]'>Name</member>"; } $xmlBody .= ""; echo $xmlBody;
  4. trying to create an array that is separating brackets, semi-colon and space from "mydata" and iterating over to create first and last name's separated into two subs... and then loop those through. so i'd like either change the way i can explode and loop the information... or place the first and second subs and skip the third sub in the array. $str = $_POST["mydata"]; $mores = explode("[];",$str); foreach ($mores as $more) { $datas = explode(" ",$more); if (array_values ($datas) === $datas) $xmlBody .= " <member name='$datas[1], $datas[0]' display='$datas[0] $datas[1]'>Name</member>"; } can someone please assist? much appreciated.
  5. 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;
  6. 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.
  7. 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 .= '';
  8. quick google search. http://php.net/manual/en/features.commandline.php
  9. 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;
  10. 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???
  11. 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 .= '';
  12. the below code and many more examples that may or may not fit your needs are at http://www.php.net/manual/en/function.preg-match.php Example #3 Getting the domain name out of a URL <?php // get host name from URL preg_match('@^(?:http://)?([^/]+)@i', "http://www.php.net/index.html", $matches); $host = $matches[1]; // get last two segments of host name preg_match('/[^.]+\.[^.]+$/', $host, $matches); echo "domain name is: {$matches[0]}\n"; ?>
  13. thank you... i'm still not getting this to work properly... i believe my issue is that i'm now not placing the field headings into $fields (and i've attempted placing all of the names of the field headings into $fields with no success... i'm receiving a bad argument warning at the implode and a Notice: Column count doesn't match value count at row 1. $files = glob("/my/file/path/US_*.csv"); $handle = fopen("$files", "r"); # ini_set('auto_detect_line_endings', true); $data = fgetcsv($handle, 1000, ","); $k = array_keys($data); $fields = array(); for($i = 0; $i < 47; $i++) { if ( !in_array($i, $k) ) { $data[$i] = 'N/A'; } $fields = 'name' . $i; } $query = "INSERT INTO tableName ( " . implode(', ', $fields) . " ) VALUES ( '" . implode("', '", $data) . "' )"; $result = mysql_query($query)or trigger_error(mysql_error()); fclose($handle); print "Import done"; mysql_close($con);
  14. went back and reviewed data... all the fields have characters, either with needed information or with N/A. and in my sql query... i'm looking for 47 positions, so i should have all of the request names that i'm inserting into, being placed into the associative array. but now i'm just lost and confusing myself a bit more... cause i feel i'm at the same spot i started from with my original code. i may have gone about it differently and not as elegantly though.
  15. i think i have a combination of: which brings me to a question... would it be better to utilize a different process of handling the data instead of fgetcsv? like one of the functions that are listed on fgetcsv page? o am i completely missing something?
×
×
  • 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.