PHP - Split An Array Into Chunks.
I have a variable on my page called, $recipe['ingredients'];
inside the var you have for example.... 100ml milk, 350ml double cream, 150ml water and so on. Now Im trying to split it up so it looks as follows <ul> <li>100ml milk</li> <li>350ml double cream</li> <li>150ml water</li> </ul> So far I have the following code..... $ingredientsParts = explode(',', $row_rs_recipes['ingredients']); $ingredients = array($ingredientsParts); while (! $ingredients) { echo" <li>$ingredients</li>";} But for some reason it doesnt work and I do not have the exp with explode to fix it. Similar TutorialsMy string is like this: line 1 line 2 .... line 3453 line 3454 etc... I want to split the string into chunks of 500 lines, do something with those chunks and then reassamble the main $string again. The last chunk doesn't need to be 500 lines it can be less. How can I do it? Hi, I am trying to organise some data from a form which is transferred to me via jQuery. Right now I can transfer the data to my php function as either serialised data. Here I need to figure out to structure my data in arrays that allows me to work with them before I save to the database.. But how do I do this? I have been fiddling with explode, and trying to flatten it and do an array_push using a "while" for every 6'th item.. What I am looking for is this: Array[$i] ( Weight=>, repetition=>, field_id=>, set_id=> exercise_id=>, planned_workout_id= ) Array[$i++] ( Weight=>, repetition=>, field_id=>, set_id=> exercise_id=>, planned_workout_id= ) The structure I can have the data in Serialised form: Weight=&repetition=&field_id=h&set_id=1&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=2&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=3&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=4&exercise_id=1&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=1&exercise_id=13&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=2&exercise_id=13&planned_workout_id=1&Weight=&repetition=&field_id=h&set_id=3&exercise_id=13 or in array form.. which is 200+ subarrays Array ( [0] => Array ( [name] => Weight [value] => ) [1] => Array ( [name] => repetition [value] => ) [2] => Array ( [name] => field_id [value] => h ) [3] => Array ( [name] => set_id [value] => 1 ) [4] => Array ( [name] => exercise_id [value] => 1 ) [5] => Array ( [name] => planned_workout_id [value] => 1 ) [6] => Array ( [name] => Weight [value] => ) [7] => Array ( [name] => repetition [value] => )
i have a set of array's with a similer layout as t127201103111200 what i need to do is split it like this t:1:27:2011:03:11:1200 (where the : is where i want the split but not add the : ). so i end up with this. $a = t $b = 1 $c = 27 $d = 2011 $e = 03 $f = 11 $g = 1200 what i think i need to do is Code: [Select] split(char1($a), char2($b), char3,4($c)...........................) but have no idea where to start. Thanks for any help Hello, I have a string that contains a directory path much like: "/images/icons" and I want to take that string through a function and explode it into an array of directories that with add my directory structure array: images icons Then if I were to send the string "/data/documents" to the function it would append to the existing array: images icons data documents Here's the code that I've got thus far: <?php $global_structure = array(); generate_structure("./images/icons"); generate_structure("./data/documents"); function generate_structure($directory) { if(!is_dir($directory)) return false; $directory_structure = explode("/", $directory); // do something here to iterate over $global_structure and add new directories to equal to current directory path making the value an empty array. } ?> I have an array like this
$rows = array( array( 'fruit.name' => 'Apple', 'fruit.colour' => 'Red', 'fruit.weight' => '0.1', 'vegetable.name' => 'Carrot', 'vegetable.colour' => 'Orange', 'vegetable.weight' => '0.05' ), array( 'fruit.name' => 'Banana', 'fruit.colour' => 'Yellow', 'fruit.weight' => '0.7', 'vegetable.name' => 'Potato', 'vegetable.colour' => 'Brown', 'vegetable.weight' => '0.6' ) ); Hi! So what I'm trying to do is split a multi dimensional array of strings ( each containing 3 strings inside of 1 array ) so I can write the results to a file. So say I had a bunch of strings inside 1 array : class File { function WriteFile ( $filename, $content ) { $list = [ $content ]; $delimiters = File :: checkDelimiter ( $content, true, false ); $fp = fopen ( $filename, 'w' ); foreach ( $list as $fields ) { $fields = File :: SplitFileByDelimiter ( $fields, ",", 3 ); file_put_contents ( $filename, $fields ); } fclose ( $fp ); } } $file-> File :: WriteFile ( $filepath . $filename, "TEST!, TEST!, TEST!, " . "TEST!, TEST!, TEST!, " . "TEST!, TEST!, TEST!" ); Instead of writing : TEST!, TEST!, TEST!, TEST!, TEST!, TEST!, TEST! ,TEST!, TEST!, TEST! to the file in a straight line, it should write it like this : TEST!, TEST!, TEST!, TEST!, TEST!, TEST!, TEST!, TEST!, TEST! Any help is ABSOLUTELY appreciated! Edited May 22 by AquariaXI Hey all, I done some research and can only seem to find solutions that involve a java applet in the browser to break up the files into parts, does anyone else know of any other pure php solutions to uploading large files and using chunks? cheers hello dear folks good evening dear PHP-Freaks,
well i am not sure if this question fits here - in miscellaneous.
but i am pretty sure that many many calc and excel-experts are here in this great forum.
what is aimed:
want to create a calendar - with 365-chunks that are imported into a caleandar form see some ideas where i can import this i posted the example-calc spreassheet that i want to import. note it has got 365 lines - for 365 days of the next year 2015 what needs to be done ; whats needs to be achieved: i need to impoort the example into the calendar form. see some of the examples -.. if i am able to import the texts (of the collumn ) in a writer or word document each line of the calc needs to get on a sheed of the word or writer. i need to know how to arrange this export of calc into the writer document. if i need to explain it more thoroughiy - just let me know! greetings you matze see some examples of calendar templates Blank daily calendar - Templates Daily lesson planner (color, landscape) - Templates note: all i need to know is to be able to export from calc to any word or calc document... see the attached sample below... Attached Files 2015_sample_version_.ods.zip 18.07KB 0 downloads My query gets the results and orders by one of the fields. Once I get the MySQL results I would like to find the first entry that has a letter as the first character of the same field that the list was ordered by, then split the results in to two parts and swap them. So that the results that have a letter at the start of the same sorted field are as the begining and the results that have the numbers as the start at the end of the array. But also so that the array works the same way as the original results string, so i can use say $results['mysqlfield'] I'm pulling 10 records here. How do I split the results in to several echos? $query = "SELECT statez, COUNT(statez)FROM mylist GROUP BY statez"; $results = mysql_query($query); $returnS=""; while($line = mysql_fetch_array($results)) { $returnS.= $line['COUNT(statez)'].",,".$line['statez'].",,,"; } echo $returnS; mysql_close($link); ?> I need the code to look like this by showing the (COUNT) number for each state. $results = mysql_query($query); while($line = mysql_fetch_array($results)) { echo $line["number_in_state1"].",,"; echo $line["number_in_state2"].",,"; echo $line["number_in_statee3"].",,"; echo $line["number_in_state4"].",,"; echo $line["number_in_state5"].",,"; echo $line["number_in_state6"].",,"; //etc.... } What's the best string function to use if i want to split a string up affter a specific character? In this case i have a var with "uploads/thisImage.jpg" i want to split this so i can create a new var value of "thisImage.jpg" hi everyone, i have a string as this one: 45,3455,66,8900,2,49,88,8,909 I need to print it with a new line every 4 numbers, as this one: 45,3455,66,8900, 2,49,88,8, 909 How can i do this? many thanks I need to split a string, but in a very unusual way. $string1 = "HelloWorld" $string2 = "AlphaBravo" $string3 = "BreakMeUp" I need the following split at each upppercase letter for this output Hello World Alpha Bravo Break Me Up i have same problem like you, if i open a small file(3 to 5mb), open normal. But, when i try open a dbf file 13mb or more, cause php.exe error; i set Mem in php.ini to 256mb(before 8mb), but doens't work. Someone have some solution, because i try find some way to clipper program input data on MySQL and dont have sucess too... Hi all, hopefully just a quickie. split is deprecated in 5.3, but i have the following to get working.. Code: [Select] $dest = split(self::__MAIL_DELIMITOR__, $this->_mails); delimitor is as follows: Code: [Select] const __MAIL_DELIMITOR__ = ',';and _mails is just a list of email addresses. Can anyone suggest a workaround? Thanks How can I split this data and then remove it? I need to split data by ; then split each one of those. $data = "page=1&data=1:21;2:34;5:57&a=yes"; So I will get: $category[0] = 1; $sub_category[0] = 21; $category[1] = 2; $sub_category[1] = 34; $category[2] = 5; $sub_category[2] = 57; I've been trying to figure out how to split up strings such as the following: A54a1, 23b, FX49s1, R231z, 77 I would like to split them up and add them to individual arrays that are as follows: index[0] -> alphabetical characters, if any, prior to the first number, if any index[1] -> numerical characters, as a number, up until the following alphabetical character index[2] -> alphabetical character(s), if any index[3] -> numerical characters following the second alphabetical character set, if any So, for example, the above strings would be separated like this: A54a1 == ('A', 54, 'a', 1) 23b == (, 23, 'b',,) FX49s1 == ('FX', 49, 's', 1) R231z == ('R', 231, 'z',,) 77 == (,77,,) I've looked into things like strpos(), but I can't figure how to determine whether a character is alphabetic or numeric. And yes, I am familiar with the function is_numeric(). Just don't know how to throw it all together to accomplish what I need. How do i specify that i want the fgetcsv() to use a ; to separate instead of a , p.s.(i have no control over the .csv file so i cant change it from ; to ,) What's the difference between str_split() and chunk_split()? They seem to perform the same task? I am trying to split a variable only if it has an integer. Here is what I want to do: $id = 1234-54678; should be split into and then placed into two variables: $id1 = 54678; $id2 = 1234; Sometimes the variable may not have a delimiter in which case I would like it to be $id1 example: $id = 54678; should go directly to $id1 = 54678; I am a php rookie and don't know which way is best to do this (explode, split, etc.) so I would appreciate any help you can give me. |