Jump to content

eo92866

Members
  • Posts

    40
  • Joined

  • Last visited

    Never

Everything posted by eo92866

  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?
  16. i guess i'm missing something... because the below method works... but it increments mysql db with more records... and still has offset errors... and where would you recommend placing a break to stop the db records from incrementing?
  17. so all of the code up to the mysql insert is: $files = glob("/my/file/path/US_*.csv"); // just to see what is there #print_r($files); $max_loop = 1; $count = 0; //loop for iterating $files into array $file and then into $value foreach($files as $file => $value) { //increment the loop by 1 $count++; //set the variable $count to variable $max_loop if ($count==$max_loop) { //create a break, because now have made the counter equal to 1 break; //get the contents of $value $contents = file_get_contents($value); } } // just to see what is there #print_r($contents); // place $value into fopen... to be opened and into array $handle, the "r" stands for read only $handle = fopen("$value", "r"); $row = 1; $i = 0; while ($i<10000) { $data = fgetcsv($handle, 1000, ","); //undefined offset error on $sql $sql="INSERT INTO tableName (name1, name2, name3, name4... this goes all the way to name46) VALUES ('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[3]."' ...this goes all the way to name46)"; $sqlData = mysql_query($sql); Notice: Undefined offset: 28 in /myfile.php on line 52
  18. many apologies... i was mistaken... not 8000 and 1000... but 800 and 1000. many apologies again.
  19. the csv file has 46 columns and over 10000 rows. these columns consist of fields that can be null values, but mainly have text, some numbers and some special characters like, @ etc. i do expect to get anywhere between 8000 to 10000 characters per row/line. an example of the data: US 9200 This is the first day. 382700 Above-12 etc... does this help?
  20. ok... i have the number of indexes in $data.... 10156. i'm just not sure where you're going with the number??? even if i change the i<10000 to i<10155
  21. the information is very unique... not just name1-46 naturally. i am placing csv data into mysql... $handle = fopen("$value", "r"); $row = 1; $i = 0; while ($i<10000) { $data = fgetcsv($handle, 1000, ","); #plus prior code here...
  22. hi... i'm getting an undefined offset for the associative arrays [28-46] in this format. $sql="INSERT INTO tableName (name1, name2, name3, name4... this goes all the way to name46) VALUES ('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[3]."' ...this goes all the way to name46)"; $sqlData = mysql_query($sql); i have read that i can prevent the notices by doing the following, but it's not working for me: $sql="INSERT INTO tableName ( 'name1' => "isset(.$data[0].) ? $data[0] : 'default value'", 'name2' => "isset(.$data[1].) ? $data[1] : 'default value'", 'name3' => "isset(.$data[2].) ? $data[2] : 'default value'", 'name4' => "isset(.$data[3].) ? $data[3] : 'default value'", #this goes all the way to name46 )"; $sqlData = mysql_query($sql); can anyone please assist me?
  23. so my final code that works... as i have the error_reporting turned on now $files = glob("/my/file/path/US_*.csv"); // just to see what is there #print_r($files); $max_loop = 1; $count = 0; //loop for iterating $files into array $file and then into $value foreach($files as $file => $value) { //increment the loop by 1 $count++; //set the variable $count to variable $max_loop if ($count==$max_loop) { //create a break, because now have made the counter equal to 1 break; //get the contents of $value $contents = file_get_contents($value); } } // just to see what is there #print_r($contents); // place $value into fopen... to be opened and into array $handle, the "r" stands for read only $handle = fopen("$value", "r"); hope it helps someone down the line as well.
  24. this is simply my idea.... first create two different html/php pages one that will be the list for your users to utilize the drop downs next one that will have the redirect information. first page that will be for your users aka htmlSelection.php <html> <body> <form action="dropdownResults.php" method="POST" name="links"> <select name="dropdown" value="options"> <option value"htmlSelection.php">Select Format</option> <option value="directory/yourTitle1.php">Your Title 1</option> <option value="directory/yourTitle2.php">Your Title 2</option> </select> <br/> <br/> <input type="submit" value="Submit Query"/> </body> </html> second page that will be for your redirect aka... dropdownResults.php <?php $drop = $_REQUEST['dropdown']; if ($drop ='Your Title 1') header("Location: yourTitle1.php".$row["your Title 1"]); elseif ($drop ='Your Title 2') header("Location: yourTitle2.php".$row["Your Title 2"]); ?> now what you want to do is place your mysql code at the top of "Your Title 1 or 2" .php files that connects/queries/closes the mysql db. read here... http://www.w3schools.com/PHP/php_mysql_connect.asp
  25. i know you mentioned that fopen doesn't work with having glob inserted... you mentioned utilizing file_get_contents... would file_get_contents be the best function to insert glob into fgetcsv too???
×
×
  • 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.