Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
When I try to split a string into an array the first element is returned as an array!
Old 01-11-2009, 07:23 PM When I try to split a string into an array the first element is returned as an array!
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
I am trying to create an array from a string as follows:
PHP Code:
$TextsArray=array(split("~"$TextString)); 
What's up?

Last edited by Sleeping Troll; 01-11-2009 at 07:33 PM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-11-2009, 07:35 PM Re: When I try to split a string into an array the first element is returned as an ar
PeachyJuice's Avatar
Super Talker

Posts: 116
Name: Michele T.
Location: Ny, Ny
Trades: 1
Two things:

1. explode() is faster than split(), and it doesn't look like you need to use regular expressions so you can change it and save some processing time.

2. split() and explode() automatically return as an array. You don't need to use the array() function. It works simply like this:
PHP Code:
$TextsArray explode('~'$TextString); 
__________________
Freelance web+graphic designer and PHP developer.

Please login or register to view this content. Registration is FREE
PeachyJuice is offline
Reply With Quote
View Public Profile
 
Old 01-11-2009, 08:59 PM Re: When I try to split a string into an array the first element is returned as an ar
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Yes, I have tried them and all variations on the theme, but no matter what I do when I split a string to create an array the first element is returned as an array! I have done this before with no problem, I am wondering if it has something to do with the latest release of php?
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 01-11-2009, 09:29 PM Re: When I try to split a string into an array the first element is returned as an ar
Decaf's Avatar
Ultra Talker

Posts: 489
Name: Adam
Trades: 0
Quote:
Originally Posted by Sleeping Troll View Post
Yes, I have tried them and all variations on the theme, but no matter what I do when I split a string to create an array the first element is returned as an array! I have done this before with no problem, I am wondering if it has something to do with the latest release of php?
PHP Code:
# Set the text and blow it to bits
$text "Split me into many parts";
$split explode(" ",$text);
/*
$split[0] = "Split";
$split[1] = "me into many parts";
*/

# Now, you can do this further by:
$split2 $split[1]; // "me into many parts";
$split2 explode(" ",$split2);
/*
$split2[0] = "me";
$split2[1] = "into many parts";
*/ 
If your problem is that you don't want your text to be put into arrays, then your out of luck. more on explode()

Also, a snippet of the code will help.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


Last edited by Decaf; 01-11-2009 at 09:31 PM..
Decaf is offline
Reply With Quote
View Public Profile Visit Decaf's homepage!
 
Reply     « Reply to When I try to split a string into an array the first element is returned as an array!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13166 seconds with 12 queries