Exploding String, Then Putting It In Array
I have a script that reads the files in a dir, then explodes each file name. The files look like this:
Artist - Album
I want the explode the characters before the " - " (the artist) so I can collect a list of artists without the album info. I'm trying to explode the filename and then have it pushed into an array but it's not working. PHP Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Exploding String
I have a script I use to explode a string and grab variables. It works great on one server, but when I use it on a separate web site it doesn't work at all. This may be a permissions issue, but other php scripts work fine.
Exploding A String
Is it possible to have the results of an exploded string into 4 different arrays?? I have many lines of $strPingCurrentLine each containing url, email size and command details. I therefore hope for a way to push each exploded $strPingCurrentLine into Quote$arUrl = array(); $arEmail = array(); $arSize = array(); $arCommand = array(); Instead of for instance $arTemp = explode(" ", $strPingCurrentLine);
Exploding An Array
I have a file with multiple lines, each line contains information broken into three parts that is separated with commas: FILE: l0p0,l0p1,l0p2 l1p0,l1p1,l1p2 l2p0,l2p1,l2p2... I want to use this information in a script, so I call the file using the following command: $file=file("myfile.txt"); This breaks up the file into an array, with each key representing a different line. I want to further break down this array efficiently as possible so that each line is exploded by the comma. I'm wanting to get an output like this: Array ( [0] => Array ( [0] => l0p0 [1] => l0p1 [2] => l0p2 ) [1] => Array ( [0] => l1p0 [1] => l1p1 [2] => l1p2 ) [2] => Array ( [0] => l2p0 [1] => l2p1 [2] => l2p2 ) ) I tried using this line: $file=explode(","file("myfile.txt")); but what it seems to be doing is just exploding the word "Array" print_r $file[0][0] => "A" print_r $file[0][1] => "r" However, explode(",",$file[0]) seems to work. How can I explode my array without having to do an explode command each time I want to use a value?
Exploding Array
Here's my problem. I am reading from a text file using this: if (!file_exists($file)) { echo "Don't exist "; return false; } $fd = @fopen($file, 'r'); if (!is_resource($fd)) { echo "Error reading "; return false; } And it works fine. The data that will be read will always be in the text file in the form of one - two - three - alpha beta kappa delta epsilon 13.5pp 29.95eu Now I want to explode that array that was read so I use this: $arrayData = explode("-", fgets($fd, 4096)); print "first=$arrayData[0] "; print "second=$arrayData[1] "; print "third=$arrayData[2] "; print "fourth=$arrayData[3] "; which will give me first=one second=two third=three fourth=alpha beta kappa delta epsilon 13.5pp 29.95eu But I need to access the last two items (13.5pp and 29.95eu) of this array to split them off as well so that the final output I need would be like this: first=one second=two third=three fourth=alpha beta kappa delta epsilon.txt numpages=13.5pp cost=29.95eu How can I do that? Do I need to further explode $arrayData[3] using a space delimiter? Is there a way to grab the last two fields only because the length of the 'alpha beta kappa delta epsilon' will not always be the same but the numpages and cost will always be the last two elements in the array.
Exploding Array
I'm having a bit of trouble here with getting an array to explode. When I echo it, its is simply writing "Array" 49 times. Basically I just need to seperate my arrays with a coma so I can select those ids from my table. Anyone got any ideas? I'm new to php so I'm stumped. Code:
Exploding An Array, Kind Of ...
I have an array as follows $sounds = array(); $sounds['sound1'] = "fishes/1/sound.php"; $sounds['sound2'] = "fishes/2/sound.php"; $sounds['sound3'] = "fishes/3/sound.php"; $sounds['sound4] = "fishes/4/sound.php"; $sounds['sound5] = "fishes/5/sound.php"; $sounds['sound11] = "bears/1/sound.php"; etc etc...... What I want to be able to do have turn the above into this: include ("sounds/fishes/1/sound.php"); include ("sounds/fishes/2/sound.php"); print ("<br>divider<br>"); include ("sounds/fishes/3/sound.php"); include ("sounds/fishes/4/sound.php"); print ("<br>divider<br>"); include ("sounds/fishes/5/sound.php"); include ("sounds/birds/1/sound.php"); etc etc I'm totally clueless as to how I might acheive it, especially including the "dividers" every two includes. Surely one of you clever folk gotta be able to spoon feed it to me? ;)
Exploding Comma Separated In Array
I'm looking to explode the comma separated values in an array like this: Array ( => 10811 [1] => 7527,7556 ) and then add the exploded value as a new key in the array...like this: Array ( => 10811 [1] => 7527 [2] => 7556 )
Putting Multiple File In Array
Is there anyway to put the contents of several file into one array? Say I have 3 files, and I want the information in each of them loaded into the same array, possible using a wildcard like *.txt. Is this possible?
Putting Content From Database Into Array
I have a problem with the following code, what i try to reach is that i want to compare a value with a value out of the database and if equal then display that else display that. The problem is that i can't put the content from a database row into an array, the following: PHP Code:
Need Help Putting Data Into Array / Removing Duplicates
I've got a variable that looks like: 31, 1, 1,1,1,1,164, 164,29, 29,29,29,37,2,2,2,2,2,2, 147,147,26,26,49, 138, 138,138,138,138,138,138,137, 137,168, 170, 170,48, 172, 44, 187, 183, 185, 195, 184, 186, 45, 46, 194, 167, 182, 181, 34, 18, 16, 25, 28, 53, 53,11, 11,10, 20, 192, 39, 54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54, 54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54, 54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54, 54,54,54,54,54,58, 58,58,58,58,58,58,58,58,58,58,58,58,58,58, 58,58, 175, 176, 180, 177, 178, 179, I'm sending it to a mysql query which will say NOT IN($variable 0) (the 0 is added because the variable ends with a comma). I'd like to remove the duplicates but have no idea how. I figured if I stick it in an array it will be easier. There is an array_unique function after all. But I have no idea how to get the data in an array. I tried $arr1 = str_split($variable); but it spit out an error, probably due to the trailing comma.
Putting An Array In A Mysql Database Table Field
I want to insert an array into my database but i've got a problem with it. Before i insert the array into the dbase i check if everything is in the array with print_r($array). Everything that should be in the array is in there so i insert it into the dbase. When i check my dbase with phpmyadmin the field that should contain my array has the word array in it so i assume the array is in the dbase. But when i retrieve the data from my dbase and check my array with print_r i get the following error: Warning: Argument to array_values() should be an array in.
Putting An Array Within An Array?
Still having fun trying to build the perfect form and validation classes and wondered if anyone can help on the following. In the following function, how can I make $validationparameters an array so it can accept multiple values that I can iterate through? Don't need the iteration part (yet). function setField($type, $name, $value, $style, $label, $validationparameter) { $this->number_of_fields++; $this->fields[] = array('type'=>$type, 'name'=>$name, 'value'=>$value, 'style'=>$style, 'label'=>$label, 'validationparameters'=>$validationparameters); } This is part written function that I will use to pass the multiple values to the array. function setValidationParameters($number, $parameter) { $this->fields[$number][validationparameter] = $parameter; } I am beginning to confuse myself and wondering if anyone can add some sanity to what I am doing.
Sorting An Array Problem, (array/string Manipulation)
I have a function that I found on google, that goes through a directory and spits out a directory tree in an array, with arrays inside of arrays, and more and more arrays inside of arrays, depending on how many subdirectories are there..... Here is a sample "directory tree" it spits out. My problem is wanting to be able to create a new array containing only the paths to all the subdirectories it finds from this array, so it is with array manipulation... Not all paths are located in the topmost array's values, but some directories are within other subdirectories and so forth.. I'm stumped on how exactly to sort through this array, whether recursively or not to grab all the 'paths' in the array period. Code:
Exploding A Word?
HAven't figured this. I have a word like 'ABC' How would I explode this? My difficulty is that there's no separator to which explode by.
"Array To String Conversion" Error When Constructing A Multi-dimensional Array
I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set of values to them based on data submitted from POST Fields. Code below: $_SESSION["increment"] = array(); $x = 0 // Counter - This will be incremented $_SESSION["increment"][$x] = array("increment_bond" => $_POST["increment_bond"], "increment_amount" = $_POST["increment_amount"], "increment_comm_date1" = $_POST["increment_comm_date1"], "increment_comm_date2" =$_POST["increment_comm_date2"], "increment_comm_date3" = $_POST["increment_comm_date3"]); It keeps throwing out that error, and does not write any of the POST Values to the array (the POST values are definitely getting sent, so that is not the problem). If I dump out the value of $_SESSION["increment"], I get "1A" ?!? I'm sure that there is a pretty simple mistake lurking somewhere - I just can't seem to figure it out.
Exploding Text File....
I want to put a text file into a form field, and then submit it to a page that will split up the text file on two criteria and then loop through each split result inserting new db records. A sample text file would be: question 1;option1;option2l;option3 question 2;option1;option2l;option3 question 3;option1;option2l;option3 I need to split it on blank lines and then again on the options so that my insert would be insert questionname, option1, option 2....into questions. Can someone help please. I know I can use explode, but unless I am missing something then its just not working for me.
Exploding Tab Delimited Line
I'm trying to create an array from a tab delimited line of text. I've tried explode('/t',$line); but doesn't seem to work. What am I doing wrong?
Imploding/exploding 2 Dimensional Arrays
I am using this to explode an array that has been imploded and passed via an invisible field... //REMAKE THE LIST ARRAY $list = explode('|',$stringlist); //COPY AND NAME THE FILE $address = "../../projects/img".$count.".jpeg"; copy($file, $address) or die("Couldn't copy the file!"); //GET TITLE NAME OF IMAGE $position = strpos($file_name, "."); $file_name = substr($file_name, 0, $position); //ADD THE FILES NAME AND ADDRESS TO LIST $temp[$file_name]=$address; $list[$count]=$temp; $count++; its for a file uploading system and i want to build a 2 dimensional array of the original names of the file and the url it will be stored at, what i cant figure out is how to correctly implode a 2 dimensional array so that it will pass correctly, here the first file gets submitted correctly but while doing the second file 'array' gets passed. can someone show me how to implode and explode a 2 dimensional array or point me to where i can find info on this.
Exploding Results Of Mysql Query
I have a table with times and dates listed like this: 0000-00-00 00:00:00 2003-09-20 20:26:22 etc etc What I want is to query the DB for the field (matchdate) and then get it to explode the ' ' to give jsut the date for me and then put it into a dropdown in a loop. this may sound easy but i too sleepy to work it out and searching aint good.
Exploding At Real Breaks Not Wraps
I am working on reading my pop3 email , and I am trying to return the header data using the function, I get this fine. The question I have is since there is no consistency to the rows, I want to take each row of data, not a wrap of a long line, any idea beyond checking if it has a : in it???
Array To String
I need to send an array by email when a specific error occurs. Is there something like array_toString() function that I can use to compose the message of the email? Something like var_dump that is stored in a string?
String From Array Value
The below variables are arrays, I want to create a string from the array values and I'm not sure how to bring them all together: $wholeNum = $_POST['wholeNum']; $fraction = $_POST['fraction']; $measure = $_POST['meassure']; $ingredient = $_POST['ingredient']; example: $string = $wholeNum.' '.$fraction.' '.$measure.' '.$ingredient
String To Array
I've been really battling with this feature. I seem to have it right up until the part of rebuilding the array from the string. Herewith is my array2string code:
Add To String Array
Can anyone tell me how to add extra strings to an exsisting array $data = array("AAA","BBB","CCC"); $data . "DDD"; // dosn't work.
Array["string"] Or Array[string]
array[string] seems to work well the same way as array["string"] - i know array["string"] is the right way to do it but does it matter ? will it change in future versions of PHP ?
Unpack String Into Array?
I'm reading 512 bytes of data from a file. The C structure that wrote the data is of this form: struct eu_data { float time_data[124]; int count, bptr, fptr; }; I'm trying to unpack it like this: $datarecord = unpack("f124timedata/icount/ibptr/ifptr", $dataline); How is "timedata" stored? How do I get at the individual numbers?
Retrieve URL Array From $string
Is there a way to retrieve an array of URL's from a text string? For example: $string = 'This is a <a href="www.site.com">string</a> of text with 2 URL's, one of which is http://site2.com' I want code that gives this array: $url_array = array('www.site.com' , 'http://site2.com')
How To Unpack A Very Big String In An Array
I need to unpack one string with more then 2000 chars in several pieces!! In perl i make this: $FORMAT = "A4 A4 A3 A7"; $string = "nameemailteladdress..."; @unpacked = unpack($FORMAT, $string); result: $unpacked[0] = "name"; $unpacked[1] = "email"; $unpacked[2] = "tel"; $unpacked[3] = "address"; But in PHP 4.02, How I do this I already try: $array = unpack("A4/A4/A4/A4"); and examples of www.php.net but nothing!!
String List To Array
I'm trying to convert a slash-delimited string to an array, but I'm wary of null elements that I want to eliminate. I'm frustrated with explode(), array_unique(), and array_pop(), and I'm wondering if there's a better way. I'm only interested in unique array elements. Here's what I've got $a = "10/20/30" should become an array where $b[0] = 10, $b[1] = 20, and $b[2] = 30. Now here's the fun part. Often my arrays will have $a = "10//" I'd like that to become $b[0] = 10 and that's all. So I tried applying array_unique() to explode("/", $a) but you have to be careful about how many elements are returned. Then I tried to use array_pop() to drop the last element if it's empty, but array_pop returns a scalar string when there's only one element left. So when you use $b = array_pop($q), sometimes there is no $b[0].
Replacing $string Within An Array
I am reading in a text file, using : file("myfile.txt"); and in this file I have a form, but instead of having the HTML I have text field for a text box, and cbox for an option box with a yes or no. I am then replacing all instances of "text field" with <INPUT TYPE="text" NAME="txtbox[]">. I have this page submitting to a page that is supposed to take the values submitted from the last page and replace all instances of "text field", in the text file, with the values submitted right now I am using Code:
Is $Settings['string'] An Example Of An Array?
I'm still pretty new to PHP and I have a question. I know that variables are preceeded by a "$" (dollar sign). Typically, a variable has one value, unless it is an array. Then it is essentially a pointer to numerous values sequential in memory. The code I'm looking at now is using the same variable name, but assigning a different "index" to it, if you will. For example, I see the following: $settings['use_default_images'] $settings['doctype'] $settings['theme_url'] And many more. What is this feature called in PHP? I looked at the reference on php.net and it isn't anywhere to be found under arrays.
Creating A String From An Array
I want to concatenate a number of db entries into a single string (forming a summery) I’ve come up with something that illustrates the principle, I can see that I need some sort of loop that reads each array element into the string, and then exits the loop - however my lack of experience has now got the better of me. Code:
Check Array For A String
I am trying to set up a blacklist for a service I'm making. My current objective is to call up a .txt file which contains one domain name per line. I then take the user's input from a HTTP post and check to see if it contains the domain name. Here is my current non working script: //take user's input (example: http://www.somesite.com/files/photo.jpg) $filename = $HTTP_POST_VARS['filename']; //load blacklist in case of abuse $blacklist= file('blacklist.txt'); //check submitted image against blacklisted domains foreach($blacklist as $site){ if (strstr($filename,$site) !== FALSE) { echo "<div><h3>This site is blacklisted</h3></div>"; exit();}} This doesn't seem to work at all. I think it has something to do with the variable types, but I am too unfamiliar with this for Google to be a viable solution.
Turning A String Into An Array
Is there any way to turn a string into an array (well obviously there is a way to do it, i just cant figure out how) i was thinking there must be a class in PHP what allows you to do that, either in a loop, or something built in. i.e. class_name("4", $mystring);
Convert From Array To String
i am having a small problem with my code i want to convert from array to String. i tried using the (string) casting but it doesnot work?
Save String Chars In An Array
Can anyone please suggest a piece of code that goes through a string and then saves the character information in one array as in the example below? $string = "Thiiss is my String"; char[0] contains "T"; char[1] contains "h"; char[2] contains "i"; char[3] contains "i"; char[4] contains "s"; char[5] contains "s"; char[6] contains " "; char[7] contains "i" and so on... What I need is to know the location of each letter in the string.
Make Associative Array Out Of String
I have a string that look something like this: $string = "weight, kg|1200|width, mm|220|prize|20000"; and I would like it to an associative array and print keys and value: weight, kg: 1200 width, mm: 220 prize: 20000 (The string above is fetched from a database) Anyone have any bright ideas how to do it?
Sort Array By String Length
I've been muddling through functions to make a small search engine. I'm at the point where I have each word and its position in an array, the word position being the key and the word as the value. Each word gets hashed to an integer value, and it's useful for me to have the values in the array ordered by their string length (in ascending order) to do this. After a gander through the array functions in the PHP manual the closest match I see to this is uasort(array,function cmp_function) Would this be the right function to use? And if it is, any idea what the function would look like to get them in ascending order of length...
Removing Element From Array Using String
I am trying the following based on an example from php.net <?php $array_of_items = array ('A','B','C','D'); array_splice($array_of_items, 'B', 1); foreach ($array_of_items as $array_of_items2) { Print $array_of_items2;}?> I expect the result to be ACD, I am getting BCD, Not sure why.
Decoding The Query String Array
I am building a very simple form that takes text and inserts data in a MySQL db. I would like my "logic" to simply insert the value in to the field in the database that matches the name from the query string. Here's the question- can I do this if I do not know how many name/value pairs are passed to the "logic" ? Can I just step through the $_POST array and use a do while $i <= count($_POST) or something? I have tried this but for some reason I cannot get a number back from the $_POST array. I am also confused about how the $_POST array is constructed. How do I reference name/value pair $_POST[0,1,2 etc...] get their "names" and "values" in to variables so I can accomplish the INSERT SQL(e.g. $name = $_POST[0,0]; $value = $_POST[0,1]; [INSERT $value INTO $name];- The MySQL fields will match $name)?
Prepend Array Keys With A String
I have looked on uk.php.net for the function I need but can't find it. Does anyone know what the function is called who's purpose is: to recurse through an array and assign values to keys whilst prepending the key name with a string specified by one of the function parameters?
Uisng A String Varibale With An Array
Okay, I am trying to us a varialble with a list of number values as my data for an array, yet when I do this it doesnt return any values from the array, i was able to temporarily fix the proble by just doing s normal array setup in my function, but the problem is I want the ability to have teh array values to be changed easily in a varibale style config/include file... Here is the code i am working with... =================================== VARIABLE.PHP (my config variables) ==================================== <?php $pid_prefix = "LPPA"; $site_domain = "www.lafayettepoker.com"; ###################################### # PAYOUT PERCENTAGE STRUCTURE ###################################### $range1 = ".60, .30, .10"; $range2 = ".50, .30, .12, .06, .02"; $range3 = "'.33, .17, .14, .12, .10, .06, .05, .04, .03, .02"; $range4 = ".25, .15, .10, .08, .07, .05, .05, .04, .03, .03, .02, .02, .02, ..02, .02, .01, .01, .01, .01, .01"; $range5 = ""; $range6 = ""; ###################################### # POINT POOL ###################################### $pool = "5000"; ?> ======================================= MAIN PART OF SCRIPT ======================================= <?php require ('variables.php'); if ($tplayer >= 5 && $tplayer <= 10) { $table = $range1; } elseif ($tplayer >= 11 && $tplayer <= 17) { $table = $range2; } elseif ($tplayer >= 18 && $tplayer <= 35) { $table = $range3; } elseif ($tplayer >= 36 && $tplayer <= 65) { $table = $range4; } elseif ($tplayer >= 66 && $tplayer <= 99) { if ($range5 == '') { $table = "$range4"; } else { $table = "$range5"; } } elseif ($tplayer >= 100) { if ($range6 == '') { $table = "$range4"; } else { $table = "$range6"; } }
Array To String Conversion Error
I have a form for users that queries the database and retrieves values, if they've already been set. Upon resubmission, the database is updated with the new information. I have a number of arrays, but I keep getting this error message. Everything looks fine when I print_r ($_POST), so, I'm not sure what the problem is. Here are some snippets of the code:
Break A String Into An Array Of Characters
I'm a little bit amazed that Google wasn't able to find me previous posts on this subject, as I'm sure it's been covered many times before, but it's possible I'm using all the wrong keywords. If I want to break a string into an array of individual characters, how do I do it? I thought explode with an empty delimiter might work, but it didn't.
Bold String From Array Of Keywords
Here is my code: <?php function boldText($string, $array){ $string = strip_tags($string); return preg_replace('~('.implode('|', $array).'[a-zA-Z]{0,45})(?![^<]*[>])~is', '<strong>$0</strong>', $string );}?> This will bold all words that contain any word in the array, so if the string is my superman cat and I search for super I would like the word super to be bold in superman so, when the results come back from my search, I would like it to display like this: my superman cat.
|