PHP - Arrays In Text Files
I have a folder of .txt files which have an array like this:
0#|#1#|#2#|#3#|#4#|#5#|#6 NOTE: All of the textfiles are md5 hashes. Every text file has an array like this, (numbers representing the data) and i'm trying to make it so i can access every array an combine it. So in the end i want to know how many text files have the number "6" for the 6th array and so on. I'm pretty new at PHP, so please be detailed. Similar TutorialsI have been working with a telephone directory that I created for a php class and it consists of three files: One file to write, one file to read and the html directory. Well, four if you include the contacts file. We have to take the file this week and create a two column table with an array from the contact file. I cannot for the life of me figure out how to get an array into two separate columns of a table with the php code. I will post the code here that I do have (the one I attempted to do the table on is scary..because as I said it's not working like I had hoped, but I did try!) Any sort of direction here would be much appreciated. I have looked through my book and online but all I can find online is examples with SQL and we aren't that far into the class yet. My book doesn't offer any sort of help with tables, just the arrays, so I am stumped and this assignment is due tonight! They have tutoring rooms but I had to take the baby to the doctor this morning and didn't make it in time and they are closed now. :-( Thanks in advance for any type of help of advice you can offer! This is my form: Code: [Select] <html xmlns="http://www.w3.org/1999/xhtml"> <head></head> <body> <form action='phoneWrite.php' method='POST'> <!--Username: <input type='text' size='15' maxlength='25'>--> <h1>Telephone Directory</h1> <br> <table align='Left'> <tr> <td>Last Name:</td> <td><input name='LastName' /></td> </tr> <tr> <td>First Name:</td> <td><input name='FirstName' /></td> </tr> <tr> <td>Street Address:</td> <td><input name='StreetAddress' /></td> </tr> <tr> <td>City:</td> <td><input name='City' /></td> </tr> <tr> <td>State:</td> <td><input name='State' /></td> </tr> <tr> <td>Zip:</td> <td><input name='Zip' /></td> </tr> <tr> <td>Area Code:</td> <td><input name='AreaCode' /></td> </tr> <tr> <td>Phone Number:</td> <td><input name='PhoneNumber' /></td> </tr> <tr> <td></td> <td><input type="submit" value="Register" /></td> <td></td> </tr> <tr> <td></td> <td><input type="reset" value="Clear" /></td> <td></td> </tr> </table> </form> </body> </html> This is the php used to write data: <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <?php if (empty($_POST['LastName']) || empty($_POST['FirstName']) || empty($_POST['StreetAddress']) || empty($_POST['City']) || empty($_POST['State']) || empty($_POST['Zip']) || empty($_POST['AreaCode']) || empty($_POST['PhoneNumber'])) echo "<p>You must enter your information.</p>\n"; else { $lName = addslashes($_POST['LastName']); $fName = addslashes($_POST['FirstName']); $address = addslashes($_POST['StreetAddress']); $city = addslashes($_POST['City']); $state = addslashes($_POST['State']); $zip = addslashes($_POST['Zip']); $area = addslashes($_POST['AreaCode']); $number = addslashes($_POST['PhoneNumber']); $NewEntry = "$lName, $fName, $address, $city, $state, $zip, $area, $number\n"; $ContactFile = fopen("contacts.txt", "ab"); if (is_writeable("contacts.txt")) { if (fwrite($ContactFile, $NewEntry)) echo "<p> Registration Success!</p>\n"; else echo "<p> Registration Failed, please try again.</p>\n"; } else echo "<p> Cannot add registration to the database.</p>\n"; fclose($ContactFile); } ?> <form action = "phoneRead.php" method='POST'> <h1>Telephone Directory</h1> <p>Last Name: <input type="text" name ="LastName" size = "20" /></p> <p>First Name: <input type="text" name="FirstName" size = "20" /></p> <p>Street Address: <input type="text" name="StreetAddress" size = "20" /></p> <p>City: <input type="text" name="City" size = "20" /></p> <p>State: <input type="text" name="State" size = "20" /></p> <p>Zip: <input type="text" name="Zip" size = "20" /></p> <p>Area Code: <input type="text" name="AreaCode" size = "20" /></p> <p>Phone Number: <input type="text" name="PhoneNumber: size = "20" /></p> <p><input type="submit" value="Register"/></p> <p><input type="reset" value="Clear" /></p> <a href="http://localhost/MillerAssignment4/contacts.txt">Read file</a> </form> </body> </html> And this is what I have so far on the table/read file: <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <?php if ((!file_exists("contacts.txt")) || (filesize("contacts.txt") == 0)) echo "<p> There are no entries in your telephone directory.</p>\n"; else { $ContactArray = file("contacts.txt"); echo "<table style = \"background-color:lightgray\" border = \"1\" width = \"100%\">\n"; $count = count($ContactArray); for ($i = 0; $i < $count; ++$i) { $CurrMsg = explode("~", $ContactArray[$i]); echo "<tr>\n"; echo "<td width=\"5%\" style=\"font-weight:bold\">Name: </span> " . htmlentities($ConNum[0]) . "<br />\n"; echo "<span font-weight:bold\">Phone Number: </span><br />\n" htmlentites($ConNum[2]) . "</td>\n"; echo "</tr>\n"; } echo "</table>\n"; } ?> </body> </html The contact.txt file is attached if you want to look at it Ok i have been working on this for a day+ now. here is my delema simple .ini text file. when a user makes a change (via html form) it makes the correct adjustments. problem is the newline issue 1. if i put a "\n" at the end (when using fputs) works great, except everytime they edit the file it keeps adding a new line (i.e. 10 edits there are now 10 blank lines!!!!) 2. if i leave off the "\n" it appends the next "fgets" to that lilne making a mess Code: [Select] ##-- Loop thruoght the ORIGINAL file while( ! feof($old)) { ##-- Get a line of text $aline = fgets($old); ##-- We only need to check for "=" if(strpos($aline,"=") > 0 ) { ##-- Write NEW data to tmp file fputs($tmp,$info[$i]." = ".$rslt[$i]."\n"); $i++; } ##-- No Match else { fputs($tmp,$aline."\n"); }//Checking for match }//while eof(old) what in the world is making this such a big deal. i dont remember having this issue in the past I tried opening with w+, and just w on the temp file a typical text line would be some fieldname = some value the scipt cycles through the file ignoring comments that are "#" ps the tmp file will overwrite the origianl once complete all i really want to know is WHY i cant get the newline to work, and what is the suggested fix EDIT: i just tried PHP_EOL and it still appends another newline Hi Guys, I am new to this site, and I regret that I have been ploughing my way through php tutorials for about 6 years, and have had great success and never really though about actually just asking for help untill now!! I am having difficulty with a script I am trying to write, basically the script is to a form creator script, to create a questionair. So I set up a simple database, with a table to hold the questionaire name and ID, and a table to hold to questionaire questions, and a table to hold the answers, so now I need to write the script. Each questionaire will have different amounts of questions on it, so I have made a script to ask how many questions are required, and then output the correct number of textboxes to input the questions onto, as follows ; if(isset($_POST['continue'])){ $assess_name = $_POST['assess_name']; $company = $_POST['company']; $num_ques = $_POST['num_ques']; $num_questions = (int)$num_ques; $i = 1; echo "<form action='create_assessment.php' method='post'><table width='800' cellpadding='0' cellspacing='0' border='0'> <tr><td colspan='2'>Assessment name : <b>$assess_name</b><input type='hidden' name='assess_name' value='$assess_name'></td></tr> <tr><td colspan='2'>Company Name : <b> $company</b><input type='hidden' name='company' value='$company'> "; while($i <= $num_questions){ echo "<tr><td>Question $i : </td><td><input type='text' name='ques[]'></td></tr>"; $i++; } echo "<tr><td colspan='2'><input type='submit' name='crt_assess' value='Create'></td></tr> </table></form>"; }else{ echo "<form action='new_assess.php' method='post'><table width='100%' cellpadding='0' border='0' cellspacing='0'> <tr><td>Assessment Name : </td><td><input type='text' name='assess_name'></td></tr> <tr><td>Company Name : </td><td><input type='text' name='company'></td></tr> <tr><td>Number of Questions : </td><td><input type='text' size='3' name='num_ques'></td></tr> <tr><td colspan='2'><input type='submit' name='continue' value='Continue'></td></tr> </table></form>"; } However, when processing the secondary form with the questions onto the next page, it doesnt seem to build the array for the "ques[]" textbox, i.e. it doesnt recognise it as an array. the next page code is as follows : if(isset($_POST['crt_assess'])){ include "../connect.php"; $assess_name = mysql_real_escape_string($_POST['assess_name']); $company = mysql_real_escape_string($_POST['company']); $add_assess = mysql_query("INSERT INTO assessments (name, company, timestamp)VALUES('$assess_name','$company','$timestamp')") or die(mysql_error()); $assess_id = mysql_insert_id(); echo "$assess_name Succeessfully added to database with the following questions : <br>"; if(is_array($_POST['ques'])){ foreach($_POST['ques'] AS $value){ $escape = mysql_real_escape_string($value); $add_ques = mysql_query("INSERT INTO assess_questions (question, assess_id)VALUES('$escape','$assess_id')") or die(mysql_error()); echo "$escape added successfully<br>"; } }else{ echo "error building array"; } }else{ echo "invalid page request."; } That script always returns the "error building array" string, so its proven that the $_POST['ques'] is not forming an array for each of the text boxes. Where am I going wrong? I have made a script like this before, but with checkboxes instead of textareas, and that script worked fine.... whats going on?! i have a file called filename.txt with the csv as below Date,cet,predict,16d Wed 02/15 @ 12Z,0.7,3.4,x Wed 02/15 @ 18Z,0.7,3.3,x Thu 02/16 @ 00Z,0.7,3.3,x Thu 02/16 @ 06Z,1.1,3.7,x Thu 02/16 @ 12Z,1.1,3.7,x i would like the date to be replaced by numbers 1,2,3... and to be an array, and also the 2nd value in each row to be an array. the number of rows is not fixed and grows day by day. so the result would be (1,2,3,4,5) and (0.7,0.7,0.7,1.1,1.1). can someone please help? i guessed that some sort of loop is needed to go through row by row, adding values to an array. I have tried the following with no success: Code: [Select] // get data from the file $data = file_get_contents('filename.txt'); // use the newline as a delimiter to get different rows $rows = explode("\n", $data); // go through all the rows starting at the second row // remember that the first row contains the headings for($i = 1; $i < count($rows); $i++){ $temp = explode(',', $rows[$i]); $date = $temp[0]; $cet = $temp[1]; $stack = array($stack); array_push($stack, $cet);} print_r ($stack); i have a text file that has spaces between each column. eg 12 12 13 22 34.5 10 13 18 88 32.5 12 33 17 23 22.3 (the actual data is weather data that accumulates a new line every 15 mins and is seen at www.maidenerleghweather.com/clientraw.txt ) each column represents a weather variable. i would like to use php to find the maximum values in each column and minimum values etc etc. how can i get the text data into arrays, so that i can then easily perform some simple stats on it? HOWEVER each line would NOT be an array. the first value in each line makes up array number one, second makes up two etc any ideas for a newbie beginner would be welcomed. Hi, I have an ajax response text string that looks something like this: "part2=true;part7=false;part9=false;..." I would like to turn this string into an array, that looks like this: part2 = true part7 = false part9 = false I know to use the explode function, but that will only break it into an array either by using the "=" or ";" as a delimiter.... Thank you for any help. Hey, I'm looking for some PHP code which can read a certain text file i have. I need to get certain information from this text file. This is how the text file looks like: metadataIngester: now executing performAction with token: 9188147351 metadataIngester: result of performAction with token:9188147351 metadataIngester: runtime (ms) for token 9188147351: 9953 inferencer: now executing performAction with token:9188147351 inferencer: result of performAction with token:9188147351 inferencer: runtime (ms) for token 9188147351: 10903 transcoder: now executing performAction with token:9188147351 transcoder: result of performAction with token:9188147351 transcoder: runtime (ms) for token 9188147351: 65456 transcoder: now executing performAction with token:9188147351 transcoder: result of performAction with token:9188147351 transcoder: runtime (ms) for token 9188147351: 83128 streamingServerTransfer: now executing performAction with token:9188147351 streamingServerTransfer: result of performAction with token:9188147351 streamingServerTransfer: runtime (ms) for token 9188147351: 12187 middlewa now executing performAction with token:9188147351 middlewa result of performAction with token:9188147351 middlewa runtime (ms) for token 9188147351: 28148 Now, there are more parts like this with an other tokenID & runtimes. I need to get the runtime for each token (in this example it will be 9953 + 10903 + 65456 + 83128 + 12187 + 28148 = 209775 (ms)). I need PHP to display the tokenID + the total time per token. Just thinking last night trying to speed some things up, how hard is it to have a text file on the server that can only be edited by PHP? Or is there a way of making a folder unreadable to anyone?, this way I could have all the text files in the non-readable (non-viewable) folder so no user could edit them? James Hey! I have a bunch of text files with one line of text ex. SHS9GW34 I'm trying to write a little php script on my local machine that will take all the files and put all the different codes in the same files in this kind of format: RGDGIDSG453 EOHBDSBN453 ERGD4535355 etc etc Thanks Hey guys, im new hear so im not shore how things work. Iv got a project where we are ment to alow users to record a bug fault in a computer, currently i have a page that looks like ths: <?php if (empty($_POST['bug_ID'])) echo "<p>You must enter a BUG ID number</p>"; else { $bugID = addslashes($_POST['bug_ID']); $name = addslashes($_POST['bug_name']); umask(0007); if (!file_exists("../../data/lab05")) mkdir("../../data/lab05", 02777); $lab05 = fopen("../../data/lab05/". "$bugID.txt", "a"); if (is_writable("../../data/lab05/NewBug.txt")) { if (fwrite($lab05, $bugID . ", " . $name . "\n")) echo "<p>Thank you entering a new bug</p>"; else echo "<p>Cannot add bug</p>"; } else echo "<p>Cannot write to the file.</p>"; fclose($lab05); } ?> this code runs fine however I also need to write a sperate page that allows for users to search and up date bugs recorded, I want them to search using the bug_ID field and we are ment to use the fgets method but am unshore, anyhelp would be much apricated. thank you Hi guys, im logging activity on my site to text files using; Code: [Select] date_default_timezone_set('GMT'); $LogFileLocation = "xxxxxxxx.log"; $fh = fopen($_SERVER['DOCUMENT_ROOT'].$LogFileLocation,'at'); fwrite($fh,date('d.M.Y H:i:s')."\t".$_SERVER['REMOTE_ADDR']."\t".$_SERVER['REQUEST_URI']."\n"); fclose($fh); This is write something like; [date] [time] [ip address] [folder accessed] I then post it like; Code: [Select] <? $fn = "xxxxxxxxxx.log"; print htmlspecialchars(implode("",file($fn))); ?> That works fine but what i want to be able to do is read/edit the text files, so the main things i need to add is; The ability to clear the log (using password for confirmation) not sure how to go about this because i don't know how to edit the text file <input name="password" type="text"> <input type="submit" value="Clear Log?"> I also need a script to read the log and alert me an ip address that isn't mine is found, maybe something like if (an ip that isn't mine == yes) echo "an unknown ip accessed something" Also lets say i have a script that checks if a name exists, how can i use a text file containing a list of names to be read by a script if (name exists in text file) echo "name exists" else echo "name doesn't exist" All these questions are similar in the fact i need to understand how to open and read text files for specific entries, hope you understand, thanks for any help. I have some fairly small text files (2K) which are parsed where certain deliminated fields are replaced with values provided in an associated array. There will typically be less than 5 replaced fields, and I plan on using preg_replace_callback to find and replace them.
I am contemplating caching the files after being parsed (note that they will only be accessed by PHP, and not directly by Apache).
Do you think doing so will provide any significant performance improvement?
If I do go this route, I would like thoughts on how to proceed. I am thinking something like the following:
Append the filename along with the serialized value of the array, and hash it using md5().
Store the parsed file using name "file_".$hash
Get the modification time of the newly created file using filemtime(), and store the value in a new file called "time_".$hash.
bla bla bla
When the next request comes in to parse a file, create the hash again.
If the file exists for the given hash name, and the time file matches filemtime(), use that file, else parse the original file.
Is this a good approach?
I'm importing some text files from my windows servers in to a SQL database, but I'm running in to what I think is some sort of issue with either a special character or something to do with UTF-8, or UTF-16... I haven't dealt with this before, so I'm really not even sure. I read in the file as such: $handler = fopen($file, "r"); $Data = fread($handler, filesize($file)); fclose($handler); The text file itself contains the data formatted like this: Quote Unable to deliver this message because the follow error was encountered: "This message is a delivery status notification that cannot be delivered.". The specific error code was 0xC00402C7. The message sender was <>. The message was intended for the following recipients. OnlineHelp@somedomain.com If I simply echo out this data: echo $Data It'll come out in Firefox like the following. And I can see FF is choosing to view it as Western (ISO-8859-1), but if I choose to use Unicode (UTF-16) then the data displays correctly. Quote U�n�a�b�l�e� �t�o� �d�e�l�i�v�e�r� �t�h�i�s� �m�e�s�s�a�g�e� �b�e�c�a�u�s�e� �t�h�e� �f�o�l�l�o�w� �e�r�r�o�r� �w�a�s� �e�n�c�o�u�n�t�e�r�e�d�:� �"�T�h�i�s� �m�e�s�s�a�g�e� �i�s� �a� �d�e�l�i�v�e�r�y� �s�t�a�t�u�s� �n�o�t�i�f�i�c�a�t�i�o�n� �t�h�a�t� �c�a�n�n�o�t� �b�e� �d�e�l�i�v�e�r�e�d�.�"�.� � � � �T�h�e� �s�p�e�c�i�f�i�c� �e�r�r�o�r� �c�o�d�e� �w�a�s� �0�x�C�0�0�4�0�2�C�7�.� � � � � � �T�h�e� �m�e�s�s�a�g�e� �s�e�n�d�e�r� �w�a�s� �<�>�.� � � � � � �T�h�e� �m�e�s�s�a�g�e� �w�a�s� �i�n�t�e�n�d�e�d� �f�o�r� �t�h�e� �f�o�l�l�o�w�i�n�g� �r�e�c�i�p�i�e�n�t�s�.� � � �O�n�l�i�n�e�H�e�l�p�@�E�l�i�t�e�R�a�c�i�n�g�.�c�o�m� � � And finally, if I try to insert the data in to SQL, the data looks like this: Quote INSERT INTO Badmail VALUES( 2 , '00360053425643112201000000004.BDR' , 'U n a b l e t o d e l i v e r t h i s m e s s a g e b e c a u s e t h e f o l l o w e r r o r w a s e n c o u n t e r e d : " T h i s m e s s a g e i s a d e l i v e r y s t a t u s n o t i f i c a t i o n t h a t c a n n o t b e d e l i v e r e d . " . T h e s p e c i f i c e r r o r c o d e w a s 0 x C 0 0 4 0 2 C 7 . T h e m e s s a g e s e n d e r w a s < > . T h e m e s s a g e w a s i n t e n d e d f o r t h e f o l l o w i n g r e c i p i e n t s . O n l i n e H e l p @ S o m e d o m a i n . c o m ' , '2010-11-30 07:17:05' , GETDATE()) So basically, I'm not really sure if I'm supposed to convert the ASCII to UTF-8 or if I just need to do a bunch of str_replace to correct the data before inserting. I'd appreciate any feedback or suggestions anyone has. Thank you. I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
So far I have managed to create an upload process which uploads a picture, updates the database on file location and then tries to upload the db a 2nd time to update the Thumbnails file location (i tried updating the thumbnails location in one go and for some reason this causes failure) But the main problem is that it doesn't upload some files Here is my upload.php <?php include 'dbconnect.php'; $statusMsg = ''; $Title = $conn -> real_escape_string($_POST['Title']) ; $BodyText = $conn -> real_escape_string($_POST['ThreadBody']) ; // File upload path $targetDir = "upload/"; $fileName = basename($_FILES["file"]["name"]); $targetFilePath = $targetDir . $fileName; $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); $Thumbnail = "upload/Thumbnails/'$fileName'"; if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){ // Allow certain file formats $allowTypes = array('jpg','png','jpeg','gif','pdf', "webm", "mp4"); if(in_array($fileType, $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = $conn->query("INSERT into Threads (Title, ThreadBody, filename) VALUES ('$Title', '$BodyText', '$fileName')"); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; $targetFilePathArg = escapeshellarg($targetFilePath); $output=null; $retval=null; //exec("convert $targetFilePathArg -resize 300x200 ./upload/Thumbnails/'$fileName'", $output, $retval); exec("convert $targetFilePathArg -resize 200x200 $Thumbnail", $output, $retval); echo "REturned with status $retval and output:\n" ; if ($retval == null) { echo "Retval is null\n" ; echo "Thumbnail equals $Thumbnail\n" ; } }else{ $statusMsg = "File upload failed, please try again."; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, mp4, webm & PDF files are allowed to upload.'; } }else{ $statusMsg = 'Please select a file to upload.'; } //Update SQL db by setting the thumbnail column to equal $Thumbnail $update = $conn->query("update Threads set thumbnail = '$Thumbnail' where filename = '$fileName'"); if($update){ $statusMsg = "Updated the thumbnail to sql correctly."; echo $statusMsg ; } else { echo "\n Failed to update Thumbnail. Thumbnail equals $Thumbnail" ; } // Display status message echo $statusMsg; ?> And this does work on most files however it is not working on a 9.9mb png file which is named "test.png" I tested on another 3.3 mb gif file and that failed too? For some reason it returns the following Updated the thumbnail to sql correctly.Updated the thumbnail to sql correctly. Whereas on the files it works on it returns REturned with status 0 and output: Retval is null Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif' Failed to update Thumbnail. Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif'The file rainbow-trh-stache.gif has been uploaded successfully. Any idea on why this is? Hello I have a simple question about file handling... Is it possible to list all files in directories / subdirectories, and then read ALL files in those dirs, and put the content of their file into an array? Like this: array: [SomePath/test.php] = "All In this php file is being read by a new smart function!"; [SomePath/Weird/hello.txt = "Hello world. This is me and im just trying to get some help!";and so on, until no further files exists in that rootdir. All my attempts went totally crazy and none of them works... therefore i need to ask you for help. Do you have any ideas how to do this? If so, how can I be able to do it? Thanks in Advance, pros I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? I am using WPSQT plugin in my blog site .I code some files in PHP also.how to add that files in plugin files.
hi all, how can i make this array dynamic. E.g, i want the numbers to be pulled from a database... Code: [Select] $s=array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" ); thanks in advance, i just cant work it out |