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
how to split a string into two variables??
Old 08-27-2008, 10:54 AM how to split a string into two variables??
digitalfusion's Avatar
Skilled Talker

Posts: 73
Name: Martin
Location: Fife, Scotland
Trades: 0
Hey all,

I'm in the middle of building a numerology script and it is essential that i can split a string into two variables so i can add the two together to get the answer i need.

Does anyone on here know how to do this??

I've spent nearly all day going through google and can't find anything on how to do it.

I was thinking of putting the string into an array and then splitting it using extract() but i don;t know how that would work??

Regards,
Martin
__________________
---------------------------------------------------

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

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

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

Please login or register to view this content. Registration is FREE
digitalfusion is offline
Reply With Quote
View Public Profile Visit digitalfusion's homepage!
 
 
Register now for full access!
Old 08-27-2008, 11:07 AM Re: how to split a string into two variables??
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Something like this? http://us2.php.net/preg-split
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 08-27-2008, 11:09 AM Re: how to split a string into two variables??
Skilled Talker

Posts: 85
Name: Ilyes Rhouma
Trades: 0
Do you want to split into two variables like that:
string: Hello world ---> string1=Hello and string2= world ?

You can do it in two ways:
split with delimiter: PHP explode
extract: PHP substr
__________________
Want a cheap and custom programmer or writer ?
Please login or register to view this content. Registration is FREE

Are you
Please login or register to view this content. Registration is FREE
? Start
Please login or register to view this content. Registration is FREE
free and earning money !
Please login or register to view this content. Registration is FREE
Ilyes is offline
Reply With Quote
View Public Profile Visit Ilyes's homepage!
 
Old 08-27-2008, 11:46 AM Re: how to split a string into two variables??
Experienced Talker

Posts: 33
Name: Toby Osbourn
Trades: 0
Will the string have a fixed amount of characters, or will the first of the two variables have a fixed amount of characters?
tosbourn is offline
Reply With Quote
View Public Profile
 
Old 08-27-2008, 04:14 PM Re: how to split a string into two variables??
digitalfusion's Avatar
Skilled Talker

Posts: 73
Name: Martin
Location: Fife, Scotland
Trades: 0
Quote:
Originally Posted by tosbourn View Post
Will the string have a fixed amount of characters, or will the first of the two variables have a fixed amount of characters?
Well the string should only be between 2 and 4 charecters long.

to give you a better idea if i had a string with 26 in it how would i split it in to two variables one with 2 and one with 6 so i could add the 2 numbers together?


Regards,
Martin
__________________
---------------------------------------------------

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

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

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

Please login or register to view this content. Registration is FREE
digitalfusion is offline
Reply With Quote
View Public Profile Visit digitalfusion's homepage!
 
Old 08-27-2008, 04:36 PM Re: how to split a string into two variables??
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
PHP Code:
$var="26";
$first=$var[0];  // $first=2
$second=$var[1];  //  $second=6 
A string is nothing more than an array of character.
You can access anyone of them by using the index. Just remember than an index start from 0, not 1 in PHP
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-28-2008, 05:00 PM Re: how to split a string into two variables??
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
To tag on Tripy's note, you could add the sum of a numeric string:

PHP Code:
$value '1234';
for (
$sum 0$i 0$i strlen($value); $i++) if (ereg('[0-9]'$value[$i])) $sum += (int)$value[$i];
echo 
$sum;  // output is 10 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-29-2008, 02:44 PM Re: how to split a string into two variables??
Skilled Talker

Posts: 85
Name: Ilyes Rhouma
Trades: 0
Again, check this
__________________
Want a cheap and custom programmer or writer ?
Please login or register to view this content. Registration is FREE

Are you
Please login or register to view this content. Registration is FREE
? Start
Please login or register to view this content. Registration is FREE
free and earning money !
Please login or register to view this content. Registration is FREE

Last edited by Ilyes; 08-31-2008 at 06:31 AM.. Reason: removed confusing junk
Ilyes is offline
Reply With Quote
View Public Profile Visit Ilyes's homepage!
 
Old 08-30-2008, 05:58 PM Re: how to split a string into two variables??
digitalfusion's Avatar
Skilled Talker

Posts: 73
Name: Martin
Location: Fife, Scotland
Trades: 0
Thanks everyone for your solutions, i have managed to get it done by using chunk_split and then putting them into an array and using list to extract them into individual vars.

Regards,
Martin
__________________
---------------------------------------------------

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

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

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

Please login or register to view this content. Registration is FREE
digitalfusion is offline
Reply With Quote
View Public Profile Visit digitalfusion's homepage!
 
Reply     « Reply to how to split a string into two variables??
 

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.29035 seconds with 12 queries