Jump to content
MakeWebGames

PHP [Explode]


Guest Drizzle

Recommended Posts

Guest Drizzle
Posted

Ok, so im trying to explode an array of items, split by a comma ",",so heres the code im using:

 

$items - explode(",",$r['cITEMS']);
echo $items[0];

 

Now i know that wont print the name, but how can i get it so both my items show up, instead of just 1?

Posted

As far as I know if you're using an array() you'd get an array to string PHP notice :-/

$list = "One,Two,Three"; // List
// Explode 
$getList = explode(",", $list);
echo $getList[0]; // One
echo $getList[1]; // Two
echo $getList[2]; // Three

Hope this helps somewhat.

Guest Drizzle
Posted

What i originally was looking for was, how to explode by ",", from a list of id's, and then print the individual item names. I achieved this with foreach(), moments after the post. but thanks anyway :)

Posted
$items - explode(",",$r['cITEMS']);
echo $items[0];

try the one below you put - not =

$items = explode(",", $r['cITEMS']);
echo $items[0];
Posted

Why should i help you when you keep sending e-mails from my e-mail to other people. IE: Pudda, and same to Pudda to me? Are you a idiot? I'm sure you are.

But here anyway.

 

$names = "a,b,c,d,e,f,g,h,i";
$names = explode(",", $names);

echo "<pre>";
print_r($names);
echo "</pre>";

 

Now you would have something like:

array
(
0 => 'a',
1 => 'b',
2 => 'c',
3 => 'd',
4 => 'e',
5 => 'f',
6 => 'g',
7 => 'h',
8 => 'i'
);

 

Now to get f you would need to do.

echo $names[5];

Done :)

Posted
         $items - explode(",",$r['cITEMS']);
    foreach ( $items AS $key ) {
  echo $key.'
';
  # You could also input a query or whatever you want in here
  # mysql_query('UPDATE `table` SET `column` = "Set Variable" WHERE `column` = '.$key.', $connect);
    }

...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...