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


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





Create A Comma Delimited String That I Can Convert To An Array Using Explode();.


I am attempting to create a comma delimited string that I can convert to an array using explode();. I have the following code: Code:

$cPath_new_a = tep_get_path($categories['categories_id']);
$cPath_new_b = str_replace("cPath=", "", "$cPath_new_a");
$cPath_new_c = str_replace("_", "", "$cPath_new_b");
$cPath_new_d = substr("$cPath_new_c", -2, 2);

$cPath_new_e = $cPath_new_d . ",";

echo $cPath_new_e;


This outputs 23,53,

I need it to output 23,53 Using the substr($cPath_new_e, 0, -1); and/or rtrim() method to remove the last character for some reason removes all of the commas. Am I approaching this the right way?




View Complete Forum Thread with Replies

Related Forum Messages:
Set An Array = To A Comma Delimited String Of Strings
is there anyway I can set an array = to a comma delimited string of strings and then loop through each of those manipulating the string. help me with the basic code for setting up the array and looping through it.

View Replies !
Create Array From Comma String
I am currently learning from the book, Eric Rosebrock's "Creating interactive websites with PHP and web services" it is a great book, but I have a question. I have a string loaded from mysql that looks like this: PHP Code:

$allowedfiletypes = '".jpg", ".tif", ".gif", ".png"'

I want to turn this into an array but its not working, I'm trying something like: PHP Code:

$allowedfiletypes = array($allowedfiletypes);

so that if I print_r it it will output something like:
[0] => .jpg
[1] => .gif
[2] => .png
etc.

View Replies !
Looping Through Comma Delimited String?
I'm wondering how I can loop through a comma delimited string in php?

my string: $string = "12499, 12498, 12497";
though the size will change depending on the query.


View Replies !
Converting Comma Delimited Field Into Array
I have an array that goes into a MySQL database (via PHP). The only way I could find to insert them into the database was using implode. It goes into the database just great, comma separated (although I would like each to go into it's own field, but it's okay for now).

The problem comes when I try to display it. Since it's comma delimited it display only the first item in the array. But there are multiple rows that should be displayed.

I'm not sure how to explode it so that it will display them all. I've tried a loop but that just looped the first item in the field (the first part of the array). Code:

View Replies !
Create A Delimited Text Array
How can I create a delimited text file to work with this script. I would like to put this first part in a text file and load it into an array so the php script can parse it. Code:

View Replies !
Comma Delimited File
I am trying to read comma delimited rows of text. The problem is that
some fields may be encapsulated in "" - particularly the text fields but
not numeric fields.

Is there a simple efficient way to parse the fields with comma but also
strip off the "" encapsulating some of the fields with php?

The problem is the "" encapsulation is optional. Some fields will have
it, some won't.

View Replies !
Statement With Comma Delimited Fields
I'm hacking into my vBulletin forum to use individuals current usernames, passwords, and membergroups to setup a premium portion of my site. I have the following query: PHP Code:

$users = mysql_query("SELECT * FROM user WHERE username='$username' AND membergroupids=ཛྷ'");

With this query my login works for those who have signed up for the premium content on the forum. One problem is if the members join multiple user created member groups, they're membergroupids will be like 32,10,34. I need my query to find if they belong to 32 and if so allow them access. So, if they belong to 32,10,34 then they should be allowed to enter, but if they belong to 10,34 they should not.

View Replies !
Create An Array From Variable Seperating The Values By Comma?
I have a variable with the following values...

$variable = "3,6,9,12";

How would I create an array from this variable seperating the values by comma?

$array = array($variable);

Above doesnt work, it doesnt split the array in seperate values, it thinks "3,6,9,12" is one value?

View Replies !
Comma Delimited Csv Has Commas Inside Fields
I need to import a CSV file into a database daily. That operation in itself is simple enough but the trouble is that some fields are quoted because they have commas inside them. How do I handle this with my import script?

It would be much better if the CSV was created with all fields quoted or used a different delimited but sadly that is not an option.

View Replies !
Regular Expression For Comma-delimited Pairs
I have a textarea form field for inputting (or pasting) pairs of data.

I need a regular expression pattern to validate each line for the following

double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return

The following comes close, but doesn't check for a carriage return at the
end of each line:

^"([0-9]?)+"([,]s?"([A-Za-z0-9]+)")*$

For example the following would return true:

"1","John"
"2","Paul"
"3","George"
"4","Ringo"

View Replies !
Reading Excel To MySql Or Comma Delimited ...
right direction on how to deal with an xls
flie.

but the only other file I have to work
with is pdf.

I'm not sure, is xls the better of two evils?


View Replies !
Stripping Quotes Out Of A Comma Delimited File?
I have a flat file that I'm trying to stick into a MySQL database. One
record per line, multiple fields per record, and many of them are null
fields which are just double quotes without a space between. It's probably
nothing really major for people who have done this before, but I'm a bit
stumped. The file is comma delimited. Every field is surrounded by double
quotes. I've done quite a bit of searching, on the php site and elsewhere,
but I can't seem to get it to strip the quotes out so I can explode the file
line by line to grab the fields.

View Replies !
Easy Comma-delimited List To Dropdown Box Converter
I was working on a simple converter when I realized that by not setting the id param of the option tag, it wasn't going to send the value of the dropdown box to my php script. I had this to start with: Code:

View Replies !
File Parsing Function For Tab Or Comma Delimited Files
I need a way to parse a file based on the delimitation of either tab or comma. Does anyone know the best way to do this that is the easiest? Also the file I am parsing might have a few empty strings between delimitation. I know about preg_split so if this is the only way could someone provide a link that explains regular expressions because i dont get it.

View Replies !
Looping Thru Array And Creating Comma Sep String
I'm trying to loop through the elements of an array and create a comma separated string of the values, and then trim off the last comma. Here's the code I have which only displays the last element of the array in the string: PHP Code:

View Replies !
Regular Expression :: Find Word Matches To Words In A Comma-delimited List
What's the *right* way to find word matches to words in a comma-delimited list. For example, if I have the following comma-delimited list of categories in a mysql db field:

gameboy, nintendo, playstation

and I do a search, I know I can use regexp to do something like:

select * from categories where regexp 'gameboy,'

Notice that I have the comma in there to match the whole word and the comma without matching part of a word (to prevent unwanted matches such as "play" to "playstation" or "game" to "gameboy"). The problem I'm running into is words that match that match the end of each word next to the comma (in this example, "boy" and "station"). What's the right way to match a word *exactly* using regexp *without* also matching *part* of a word.

View Replies !
Smarty - 'explode' String Into An Array Or 2 Variables
I've a smarty var, like this:
{$var}
that is equal to: ttttttttttttt|zzzzzzzzzzzz

It can be any size, the important is that they are separated by the '|'

How do I 'explode' that into an array or 2 variables in the smarty template
?

So I can just use:
{$var[0]} = ttttttttttttt;
{$var[0]} = zzzzzzzzzzzz;

View Replies !
Explode Function To Split Up A String And Turn It Into An Array
I'm using PHP explode function to split up a string and turn it into an array. All works fine except the array keys are automatically started at [0] then [1] etc. etc. How can I explode the string and have my array keys starting at [A] then [b] then [C] etc.. etc..?

View Replies !
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 !
Convert String To Array
With a string like this:

$Data = "45,'Dog',33.2,'Cat','Bird'";

I need this result:

$Arr = array ($Data);

$Arr[0] = 45
$Arr[1]=Dog
$Arr[2]=33.2
$Arr[3]=Cat
$Arr[4]=Bird

View Replies !
Convert Two-Dimensional Array To String
I'm trying to convert a two-dimensional array to a string that I can put in a database. It needs to be searchable so the serialize() function will not work. I found a script at php.net that will implode a multi-dimensional array and it works fine. The script is: Code:

View Replies !
How To Convert Array To String, And Vice Versa
I have some items, numbered from 0 upwards. Some of them may have a string attached. All these items need to be represented in a single already existing database record. So, I thought of taking an array, as it might be looking thus (the values are all strings):

View Replies !
Convert Number To One With A Comma
How can I convert "2000" to "2,000?"

View Replies !
Search String Delimited In Another String
I have a string (Website referrer).

Example: http://www.google.com/search?q=MY STRING HERE&hl=tl&client=firefox-a&channel=s&rls=org.mozilla:en-US:official&hs=dXZ&start=30&sa=N

I need to extract the keywords searched (example in the above case: "MY STRING HERE").

I think I need the string between "q=" and the next appearing "&".

How can I do this?

View Replies !
Parsing A Delimited, Encapsulated String
i've used fgetscv() before. It has some kind of built in logic to determine when a comma is inside a field versus when it's used as a delimiter and works quite well. i would like to put together some kind of preg_match expression that can take a delimited, encapsulated list of values and return all the elements. can some preg pro help me develop this expression?

View Replies !
Delete String After Comma
How would I truncate a string after a certain character? I don't know the index of that character.

I think this is close, but I need to replace the 18 with the index of the comma in the variable mystring since I won't know where the user put in a comma.

$mystring = "Hello I'm a string, and I have a comma.";
$mystring = substr_replace($mystring , '', 18, -1);

my result of echoling $mystring would be: Hello I'm a string"

View Replies !
Count Comma Separated Values In String
PHP form that checks $name doesn't already exist and then inserts them into mySQL database. All works except for the $counted variable. $list is a string that looks something like this: 123,2536,2346,332,546.

So in this instance $counted should have a value of 5 because there are 5 values in the string. But it gets inserted as 0. Cannot see what I am doing wrong. Code:

View Replies !
Split String Each Of 3 Digits Of It With Comma From Right Side.
i have a variabale. it is number. i want to split each of 3 digits of it with comma form right side. example. PHP Code:

$test1=51345786;
echo $test1;

i want to show it as this: 51,345,786. anybody know how do i show as it?

View Replies !
Var String Explode?
I exploded a url string into an array like so:

type=eating
numrec=2
drink0=milk
fruit0=apple
dessert0=icecream
adate0=05/02/2002
drink1=beer
fruit1=peach
dessert1=chocolate
adate1=06/02/2002

Note that the variables end with a digit, starting from zero. The first two vars tell what type of posting it is, and how many posts there are. Here we have 2. What I want to do is to make insert statements for MySQL for each variable.

Example: insert into mytable (drink, fruit, dessert, adate) values ("milk", "apple", "icecream', now());

And then another insert -
insert into mytable (drink, fruit, dessert, adate) values ("beer", "peach", "chocolate", now());

Any ideas how I can take these vars I exploded and get rid of the digits at the end and make them into insert statements?

View Replies !
Explode String
how do you explode string with two conditions, space and newline?

i use strtok but i could only use 1 condition
i cannot use the 2 condition space and newline

i want to explode a string with if a string has a space and newline?
how do i do that?

View Replies !
Explode A String
We have a database that has a field called "response". This field contains a bunch of lines like this -

x_trans_id=1234567
x_response_code=true
x_idnum=7458393
x_amount=95.00

We need to extract each line from this field and place them into an array. More specifically we need to pull out the x_trans_id field. Sometimes there are many arameters listed, sometimes only a few are listed, ommitng the x_trans_id. I tried parse_str($string, $dataArray);, but that put everything under one key in the array. How do you go about "tokenizing" a string into an array delimited by lines?

View Replies !
Array Explode Problem Result In A 6 Item Array
I have the following:

$BB_Basket = "basket=¦APL6007,2.00¦AVX8900,1.00¦ARCAV500,1.00";
$basket_containers = explode('¦', $BB_Basket);
unset($basket_containers[0]);
print_r($basket_containers);

This results in

Array ( [1] => APL6007,2.00 [2] => AVX8900,1.00 [3] => ARCAV500,1.00 )

Now when I try to explode further with

$basket_items = explode(',', $basket_containers);
print_r($basket_items);

This results in

Array ( [0] => Array )

This should result in a 6 item array. Any ideas what I'm doing wrong?

View Replies !
Regular Expression That Will Split A String Into Several Parts With ',' (comma)
with a regular expression that will split a string into
several parts with ',' (comma) as the separator, but NOT where the separator
is enclosed in parentheses. For example, take the string "field1,
CONCAT(field2,' ', field3) as field23, field4". I would like to be able to
split this into the following:
[0] field1
[1] CONCAT(field2,' ', field3) as field23
[2] field4

View Replies !
How Can I Explode A String On Every Char?
$string=explode("", $number)' I have a string that I need to 'explode' at every character, but I can't figure out why? Any Ideas?

View Replies !
Search String After Explode
How to search the string after explode

$name=$_POST['name']
$lines= file(data.txt);
foreach ($lines as $line) {
       $text_line = explode(":" , $line);
}

Search the name in $text_line[0] whether the name is present or not

View Replies !
Explode() Splitting String
I want to parse my css file and split it up into its individual components, first split with { then with : then with ;and } so i can get all the individual values.

I seem to beable to only spit once with explode and { and wont let me split it again?

View Replies !
Seperating An Array With A Comma
I'm trying to seperate the output of an array with a comma. I can't figure out how to eliminate the last comma. Here is my code:

$result = mysql_query($query,$connection) or die (mysql_error());
$fw = fopen("/var/www/html/ecast/windex/graph.html","w");
fwrite($fw, "/ ");
if ($new_rows = mysql_fetch_array($result)){
do{
fwrite($fw, $new_rows[0]);
fwrite($fw, ", ");
}while($new_rows = mysql_fetch_array($result));
}
fwrite($fw, " /");
fclose($fw);
?>
Output: / 85, 86, 87, 89, /
How can I eliminate that last comma?

View Replies !
Removing A Comma From The End Of An Array
I am reading a file into an array using this:

$listFile = "add2db.txt";
if (!($fp = fopen($listFile, "r")))
exit("Unable to open the input file, $listFile.");
$buffer = fread($fp, filesize($listFile));
fclose($fp);

The very last character in that $listFile will always be a comma. What I need to do is remove that last comma (and only that comma) from $buffer before I can continue on. What do I need to do to accomplish this?

View Replies !
Explode Array Created An Automatic Key For Each Row In The Array.
I have a string, like this:

Userid1 Pass1
Userid2 Pass2
Userid3 Pass3
Userid4 Pass4

Each column is tab separated. I want to explode it into an array so that the userid will be the key, and the password the value. I tried to do it like this:

$array = explode(" ", $string); // Where $string is the string above.

However, this returned both the userid and the password as the value, and created an automatic key for each row in the array.

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

View Replies !
Display Specifc Field From Explode String
I am trying to display a single field from an explode string. I have no idea how to do this. The script already explodes the string and loops the data displaying it in table format. Code:

View Replies !
Explode Function To Retrieve Individual String
If one has used the explode function to retrieve individual string i.e. $attribute from a table, can tt individual string, aft being exploded, be placed as a parameter of a recordset i.e. $rs[$attribute] to retrieve values from another table?

View Replies !
Remove All Empty Values When I Explode A String
I remove all empty values when I explode a string.

$friends = "jeff,john,,,clark";

$friendsArray= explode(",", $friends);

View Replies !
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 !
Explode Array
I have an array name, text=value, text=value, name, text=value, name,.... and I want to do something like:

for($n = 0; $n < count($a), $n++){ //where $a is the array
$b = explode ("=",$a[n]);
}

So that I get a new array $b looking like name,text,value, text,value.

View Replies !
Explode Into An Array?
I'm trying to do: explode some data into another array. I will have the code in a loop so that the data in all elements of $RowData gets split up.

I would like $ZoneCodes[0] to contain 4 elements, but I would like them to be in the next dimension. i.e. [0][0], [0][1],[0][2],[0][3] Code:

View Replies !
Explode My Array
i have a loop which stores the values in the array $store...i am using the following script after storing the values in $store now if $store[0 or whatever]="john doe" i want the $link as "john_doe" i tried ereg_replace but that also dont seem to work..so please guide in either cases Code:

View Replies !
Using Explode, On An Array?
Our website has a spanish and english version, the data for both languages are pulled using an arrays of arrays. I have one file that contains all of the arrays, here is an example of one

$products = array{
"dirtbike"=>array("dirtbike_eng","dirtbike_sp"),
}
A session variable is set (0 for English, 1 for Spanish) and the appropiate translation is pulled out of the array based on that.

It works great, easy to update and change things on our site...but now we want to take the task of translating and updating the page out of the hands of our web designer (me) and let operations do it.  They want a simple text file that they can edit and just upload to the web server for the changes to take effect...here is an example of what I have given them (translation.txt)

ID ------ English ----- Spanish
dirtbike | dirtbike_eng | dirtbike_sp

I can read the translation.txt file fine using $data=file(translation.txt);
Now it puts each line into an array.   What I want to do, is use explode on each line (using a ' | ' delimiter) and output each line into it's own array of arrays. Code:

View Replies !
Explode And Array
how to explode using for example:

$domain_handle= explode("", $rec_handle);

View Replies !
How To Explode Array From File?
contents of myfile.txt = 5035|9638742|11938 // (one line of text)

$myfile = "/home/path/public_html/myfile.txt";
$totals = file($myfile);
$var = explode("|", $totals[0]);
$i = number_format($var[0]);
$k = number_format($var[1]);

For some reason this is acting funny. I am getting a null value for $k for some
reason...

Is there a better way to do this?

View Replies !
Array Explode Problem
I have the following: Code:

$fontfind .= &#3915;,'
$fontfind .= &#3925;,'
$fontfind .= &#3935;,'

$found = explode(",", $fontfind);


When I do:


Code:
print_r(explode(",",$fontfind));


It prints
Array ( [0] => 15 [1] => 25 [2] => 35)

but
print $found[0];

It prints
1

What's going on?

View Replies !
Explode Into Array Question
I have a 4 character string which can be any 4 characters in any position within the string itself and I want to explode it into an array.

Normally I would explode it using a delimeter such as a comma or a space but how do I do it when there is no delimeter??

View Replies !

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