Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP






SuperbHosting.net & Arvixe.com have generously sponsored dedicated servers and web hosting to ensure a reliable and scalable dedicated hosting solution for BigResource.com.







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].


View Complete Forum Thread with Replies
Sponsored Links:

Related Messages:
Seperate A String Into A List
I have a field in a database table named "features". It has a value of: feature1,feature2,feature3,feature4,feature5 (and so on) I want to display the features in a bulleted list, like this: Code:

<li>feature1</li>
<li>feature2</li>
<li>feature3</li>
<li>feature4</li>
<li>feature5</li>

View Replies !   View Related
How Do You Convert A TCL List Into A String That PHP Can Read?
I have a TCL proc that needs to convert what might be a list into a
string to read

consider this:

[set string [PROPER_CASE {hello world}]]; # OUTPUTS Hello World which
is fine for PHP

[set string [PROPER_CASE {-hello world}]]; # OUTPUT {{-Hello}}
World, which PHP will print literally as {{-Hello}} World, instead of
-Hello World

Is there an easy way for TCL to brute-force a list into a
strictly-string-only format to prevent this potentially ugly display
from being displayed by PHP/etc.?

View Replies !   View Related
Splitting A String Into A Bulleted List...
I have a long string of text. Throughout the string, there is the string of characters "&&&&" (four ampersands). Whenever that "&&&&" shows up, I'd like to split the string, and put each split into a list... Code:

View Replies !   View Related
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:

View Replies !   View Related
List The Value From The Array
I have a textfield like:

<input type="text" name="cant[]">

on the next page i have 10 textfields like this .. so i have an $cant array.

how can I list the value of them from the array ? with foreach  I suppose but how ?

View Replies !   View Related
Take The List From Array
Array 1=
If I get an array of FRIEND_ID numbers

Array 2=
and an array of BULLETIN_ID numbers and somehow in this array the USER_ID of the user who created it

Can I take the list from array 1 and find all matches from array2 where the FRIEND-ID in array 1 matches the userid in array 2 and have the result make a new array?

View Replies !   View Related
Array And List
trying to split up a comma seperated string into an array and then list, however having some problems, after some assistance if at all possible. I currently have a value, in $r which is 4 values seperated by commas. Im trying to put them into an error and then I try to put them in a list. I code im using.

$r = '1,2,3,4' //this is my variable
$urlstring = array($r); //put variable into array
list($one, $two, $three, $four) = $urlstring; // problem here is that all of the values fro $r get put into the first variable in the list, $one.

View Replies !   View Related
Making A List Box From An Array
Im trying to make a combo box from an array in PHP. So far I have this, but can't think how to make it use the values in my array too. PHP Code:

View Replies !   View Related
Setting A List Into An Array
I need some help creating a calendar display of sorts. I have a list of days as headings and under each day a list of events. Each event can have multiple bands performing.
I have two tables: tbl_events & tbl_bands

tbl_events contains the date, and show info and a field called band_ID which is a comma delimited list of each bands unique band_ID from table tbl_bands. Here's my problem. I want to take that list output: tbl_events.band_ID = 1,2,4,5,6

and set it into an array. If I set $band = array($rst["band_ID"]);

and echo $band[0]; I get 1,2,3,4,5,6 what i need is:

$band[0] = 1
$band[1] = 2
$band[2] = 3, etc....

View Replies !   View Related
Drop Down List From An Array
I want the array to contain a valid year of birth for anyone between the ages of 16 and 80. I'm pretty sure this code is correct.(though it might be a bit sloppy to all you pros) Code:

View Replies !   View Related
Array: Re-generate The Key List?
I have a script that read information from a directory (using scandir()), and puts it in an array.

Now I want to filter out all files and unvalid directories (ie: '.' and '..'), so that I keep the normal/visible directories.

Than I loop through the array with a while(isset($array[$i])).

When I use array_filter() to filter out the unwanted files/directories from the array, it will also delete the keys. So the keys arent for instance: 0, 1, 2, 3, 4, 5   but: 2, 3, 5

When I loop through the array it will say: key 0 (in the beginning, when $i = 0) is not set and so it will stop. How can I re-generate the keys so there wont be gaps between the numbers?

View Replies !   View Related
List ($d, $row) = Each ($array) By Reference?
I always thought that

while (list($d,$row) = each($array)){
$row = 5;
}

would operate by reference, so that $array is filled with 5 after
this.
Instead it only seems to work with

$array[$d] = 5;

Can I use a & somewhere to do that?

View Replies !   View Related
Need Function: Split String By List Of Strings And Return Delimiters And Extra Text
I am looking for a function that takes in a string and splits it using a
list of other strings (delimiters) and can return the delimiters as well
as the extra parts of the string. I was trying the split with a regex
built up of the delimiters separated by "|", but it doesn't return the
delimiters which I need. Code:

View Replies !   View Related
How To Create Html List From Such Array ?
I've got an example array like this:

$myArr = array(
array("jj", "0", "jjj"),
array("ee", "0", "eee"),
array("bb", "ee", "bbb"),
array("ll", "ee", "lll"),
array("ff", "0", "fff"),
)

Where each row is an array with columns: id of list element, id of parent
list element ("0" means main node) and content of the element. So, from my
array I'd like to create a list like this:

<ul>
<li>jjj</li>
<li>eee
<ul>
<li>bbb</li>
<li>eee</li>
</ul>
</li>
<li>fff</li>
<ul>

View Replies !   View Related
Dynamic Drop-down List In Array
Q. How do I create a dynamically-generated drop-down list for use in
an array.

I'm using PHP with a MySQL database (through phpMyAdmin)

My database table is called com_courses, and I want to pull the
distinct 'title' fields and have them appear as a drop down menu for
the user to select in a form.

Here is my array, with (at the moment) manually-entered 'titles'
(which I now need to be dynamically generated from my database field:
'com_courses.title'

array (
"coursetitle",
"Course Title:",
$EXTRA_SELECTLIST,

array ("Report Writing", "Recruitment & Selection", "Presentation
Skills", "Essential Telephone Skills", "Time Managememt", "Customer
Care", "Other"),
0
),

I am not an experienced programmer, but can play around with php to
customize programs. I've read up on arrays (I bought a "Programming
with PHP and MySQL" book, but it just stops short of this problem). I
can't figure this one out.

View Replies !   View Related
Array List Menu Problems
I am trying to store values from a List Menu into an sql database table as an ARRAY. However, when I select the multiple values from the form, it only stores the selected values as 'Array' in the SQL table. Here is the Select Statement:

<select name="NOTES[]" size="9" multiple="multiple" id="NOTES">
<?php
do {
?>
<option value="<?php echo $row_literarydevices['LDEVICE']?>"<?php if (!(strcmp($row_literarydevices['LDEVICE'], $row_Recordset1['NOTES']))) {echo "selected="selected"";} ?>><?php echo $row_literarydevices['LDEVICE']?></option>
<?php
} while ($row_literarydevices = mysql_fetch_assoc($literarydevices));
$rows = mysql_num_rows($literarydevices);
if($rows > 0) {
mysql_data_seek($literarydevices, 0);
$row_literarydevices = mysql_fetch_assoc($literarydevices);
}
?>
</select>

Can anyone offer a reason to why the values are not being stored?

View Replies !   View Related
Multidimentional Array To Html List
how do i convert a multidimentional array:

Array (
[option 1],
[option 2] => Array ( [option 2 - part 1] => Array ( [Temp], [Temp 2])),
[option 3])

To a html list that looks like this: HTML Code:

View Replies !   View Related
Indented Text List To Array
I'm trying to get a tabbed list into a structured array and can't seem to get it. I'd like the get from this: PHP Code:

<?php
$contents = array(
    'Level 1 Item 1',
    'Level 1 Item 2',
    " ".'Level 1 Item 2 > Level 2 Item 1',
    " ".'Level 1 Item 2 > Level 2 Item 2',
    'Level 1 Item 3',
    'Level 1 Item 4',
    " ".'Level 1 Item 4 > Level 2 Item 1',
    " ".'Level 1 Item 4 > Level 2 Item 1 > Level 3 Item 1',
    " ".'Level 1 Item 4 > Level 2 Item 1 > Level 3 Item 2',
    " ".'Level 1 Item 4 > Level 2 Item 1 > Level 3 Item 1 > Level 4 Item 1',
    " ".'Level 1 Item 4 > Level 2 Item 1 > Level 3 Item 1 > Level 4 Item 2',
    'Level 1 Item 5',.

View Replies !   View Related
Dynamic Drop-down List With Array - Question
Can anyone out there give me a pointer regarding creating a
dynamically-generated drop-down list connected to an array?

And is that question as clear as chocolate spread?

Here's what I've got. I'm using PHP and MySQL database. I'm customizing
some calendar software, and I want the user to fill in a form by
selecting a title from a drop-down list, generated by my MySQL
database. However, the program I'm customizing uses arrays, which is
where I'm stumped.

What do I need to add to this code to make the array of titles(eg
"report writing" etc) come from my database, rather than the
manually-entered values that you can see here.

The field I want to pull from is called com_courses.title

array (
"coursetitle",
"Course Title:",
$EXTRA_SELECTLIST,

array ("Report Writing", "Recruitment & Selection", "Presentation
Skills", "Essential Telephone Skills", "Time Managememt", "Customer
Care", "Other"),
0
),

I hope it's not cheeky to ask this,
BTW I bought a book on Programming with PHP and MySQL, but it doesn't
answer this question,

View Replies !   View Related
Retrieve Array From FORM List Of Values?
I have created a form where a user selects 2 items from a list of 8 values.
That form field is called "choices" and returns a value to the php file as
$choices. This form posed no problem when I only allowed a single item to be
selected, but the client now needs to have 2 items selected at a time.

The problem I'm having is that I don't know how to turn the multiple
selections on the form in to an array. I thought the $choices variable
would automatically become an array, but
Using[color=blue]
> for ( $i = 0; $i<2; $i++ )
> echo "$choices[$i] ";[/color]
only returns the first two letters of the last selected item value.

And
[color=blue]
> foreach($choices as $articles)
> echo $articles. ' ' ;[/color]

Returns an invalid argument.

While echo $choices returns the second item selected in the list, but not
the first.
It appears that the variable is replacing the first item selected with the
second rather than returning an array.

View Replies !   View Related
Create An Array From A List Of IDs Within A Database Table
I need to create an array from a list of IDs within a database table. The table consists of 3 fileds, a unique ID, a user ID and the last is an int value (item number)

eg
1 3 7
2 4 5
3 3 2
etc...

How would I go about using this query

$query1=mysql_query("SELECT itemnumber FROM table WHERE userid = '{$user}'");

Would i be right in thinking I can use:
$array = mysql_fetch_array($query1);

to store all the item numbers associated with the user specified in the first query?

View Replies !   View Related
Cause Array To List As Separate Rows In MySQL
I want this array to post as separate rows in MySQL instead of one row with the array....

(thanks either way) <input type="checkbox" name="box".$boxId."[]" value="".$fields['boxvalue']."" ".((in_array($fields['boxvalue'],$selectedValue))?"checked":"").">

Code:

View Replies !   View Related
Array Form A Comma Delineated List
What's the best way to create an array from a comma delineated list?

I have a string assigned to a variable that looks like this: 1,2,3,4

And I would like to create an array so that $arr[0] = 1 and $arr[1] = 2 etc.

It seems so simple but I just can't crack it.

View Replies !   View Related
Array String Into Associative Array
On one server I have a mysql query pulling data out of a database, and then printing the results. These results are then pulled from another server Code:

View Replies !   View Related
Print Array In List/menu Form Object
how i print a full column array into a list/menu form object, so that the text links to their respective page.....it is basically for a list of interviews so you click on the band name and then goto the interview page.

View Replies !   View Related
Reading HTML Unordered List Into Multidimensional Array
I have some software (Wordpress, actually) that is sending HTML code of an unordered list when I call a particular function. I want to make that list into a multidimensional array. So something like this: Code:

View Replies !   View Related
Array Problem... - Store This List In $_SESSION['liste'];
the user selects 6 numbers in a list I have to store this list in $_SESSION['liste']; (I cant do it differently) the list is stored like that: 34-21-44-32-12-11 (cant do it differently either)

what I need to do is to explode the array, get rid of the - , sort the values in ascending order and send them to my table as a string. so in the end I should have: 111221323444

I tried using a variation of laserlight's script (given in a previous post) without success... hope that someone will have time to give me a hand again in telling me what I could change in saberlights script to make it work.

View Replies !   View Related
How Do I Find A Word In A Sentence From The List Of Words In An Array?
I have few list of words (needle) I want to find in a sentence (haystack). After a word is found, how would I echo that word? Is there a way to have a multi array so:

if the sentence contains word1,word2 or word3 then echo "coding"
if the sentence contains word4,word5 or word6 then echo "forums"

<?php
$title_of_the_item = "This would be the sentence being pulled.";
$words_from_title = explode(" ", $title_of_the_item);

$word = array("structure", "php", "sentence", "pulled");

if(in_array($word,$words_from_title)){
//even though two words are found in the array, use only 1
}
?>

View Replies !   View Related
"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.

View Replies !   View Related
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

View Replies !   View Related
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:

View Replies !   View Related
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.

View Replies !   View Related
Array To String
I have a array like so

// results from db
$v[0] = 'blue'
$v[1] = 'red'
$v[2] = 'green'
// the size of the array can change based on the number of the colors for each product
// I need to output it in a input text box like the following $value = 'blue,red,green'
// I figure some type of loop but I' don't know which one

View Replies !   View Related
Get Array From String
I would like to store data from a string in a database after some stripping. So for example:

<li><a href="xxx">yyy</a> - zzz
<li><a href="aaa">bbb</a> - ccc

In this example (which is one string) I would like to store the variable data in a MySQL table. In order to do that I need to first get the variable data from the string, which I can manage I think. But how do I get the data into the database? Do I need to insert the data into one or more arrays? And how can I then insert it into the table?

View Replies !   View Related
String From Array
I have an array

Array
(
[0] => SamplePictures/Blue hills.jpg
[1] => SamplePictures/Sunset.jpg
[2] => SamplePictures/Water lilies.jpg
[3] => SamplePictures/Winter.jpg
)

View Replies !   View Related
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 ?

View Replies !   View Related
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?

View Replies !   View Related
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')

View Replies !   View Related
How To Add String Elements To The 1 Array
I have an array that contains numbers in string elements , i want to convert
this to integers, i have made a for loop that uses the number of elements in
the array and then adds 0, thereby converting it to an integer.
//$chars is the array of strings

for ($i=0; $i<$numpoints; $i++) {
$array = array($chars[$i] + 0);
}

I dont know though how to add all these elements to the 1 array, it
replaces each element in the array with the new item,

View Replies !   View Related
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!!

View Replies !   View Related
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:

View Replies !   View Related
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.

View Replies !   View Related
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:

View Replies !   View Related
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.

View Replies !   View Related
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);

View Replies !   View Related
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?

View Replies !   View Related
Make A String Into An Array
I know there's a simple function to do this just can't remember it. Say I have a string with spaces in it like this: jpg jpeg gif png. How do I break this into an array or manipulate each piece separately basically (I need to check each file type with a string of file types).

View Replies !   View Related
Array Exists In A String
How am I able to use an associative array key to search for a string and echo the value?
PHP Code:

<?php
$haystack = "My name is Allen";

//works with this style array
$names = array("Mike", "Joe", "Bob", "allen");
echo arrayinstr($haystack, $names);//echo's allen

//How do I get associative style arrays to echo the sex (male) instead of "allen"? (male,female,alien)
$names["Bob"] = male;
$names["Sally"] = female;
$names["Charlie"] = male;
$names["Allen"] = male;
$names["Android"] = alien;

View Replies !   View Related
Find A String In Array
i have this array:

$str = array("apple is red", "banana is yellow", "pineaple is tropical fruit", "coconut is also tropical fruit", "grape is violet");

i want to find string "coconut" inside $str and put the whole string "coconut is also tropical fruit" into variable $coconut. Code:

View Replies !   View Related
Occurances Of A String Within An Array
I have an array:

$myarray = "A1&1&^B1&1&^C1&1&^D1&1&^B1&1&^"

You can see that this is an array within an array, The first set of information is separated by the ampersand while the array itself is separated by a karat.

Doing a explode of ^ I would get:

$myarray[0] = A1&1
$myarray[1] = B1&1

Doing an explode of & I would go
...

View Replies !   View Related
File_get_contents Array/string
PHP Code:

$content = File_get_contents( "http://www.counter-strike.net/" );

This works, PHP Code:

$matches[0] = $url;
$newcontent = File_get_contents( $matches[0] );

But this doesn't :/ I've got the syntax wrong, does it need quotes or something?

View Replies !   View Related
Random String From Array
If i wanted to pull a random string from an array, lets say for like a quote of the day

$quotes = array('quote1','quote2','quote3','quote4');

$todays_quote = ?

What function could i use to provide the variable $todays_quote with a quote from our list?

View Replies !   View Related

Copyright © 2005-08 www.BigResource.com, All rights reserved