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
PHP Parsing; Possible? (please help)
Old 03-30-2009, 10:16 AM PHP Parsing; Possible? (please help)
Skilled Talker

Posts: 68
Name: Avi Zolty
Location: Atlanta
Trades: 0
Hehe, that's a lot of P's
Anyways.. I don't know how to do this, and i'm sorry if this is in the wrong forum... if it is, where should I try instead, (like what language would be best?)

Basically I just want the script to do the following:
1) figure out how many letters/characters are in a word... and label them as variables. My PHP script needs to basically "break down" that is inputted into a text-field, into each seperate letter.

Is this possible? What language would be ebst do this? (i'd LIKE php..)
__________________
"If you say something interesting, people will remember your name" ~ Anonymous


Please login or register to view this content. Registration is FREE
.asp <- Irony
Zoltar1992 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-30-2009, 11:26 AM Re: PHP Parsing; Possible? (please help)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Just to clarify, you want to get the length of a string and convert it to a character array?

This should do it:

PHP Code:
$text "Text";
$length strlen($text);
$chars = array();

for(
$i 0$i $length$i++)
{
     
$chars[] = $text[$i];

__________________

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
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-30-2009, 11:28 AM Re: PHP Parsing; Possible? (please help)
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Your description is i bit blurry. Do you want to split the text into seperate letters and store each in a seperate variable, like in an array?

Lets say you've got the text 'Hello wolrd!'. Do you want this?
PHP Code:
$myLetters = array('H''e''l''l''o'' ''W''o''r''l''d''!'); 
If so, this should to the trick.
PHP Code:
$myText 'Hello World!'// From your text field, or other source
$myLetters = array();
for (
$i 0$i strlen($yourText); $i++) {
   
$myLetters[] = $myText{$i};

EDIT: Ah, you got before me Matt
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 03-30-2009 at 11:30 AM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 03-30-2009, 11:40 AM Re: PHP Parsing; Possible? (please help)
Skilled Talker

Posts: 68
Name: Avi Zolty
Location: Atlanta
Trades: 0
yes thank you both!
for interests sake... (I know I shouldnt be posting JS in a PHP forum.. so sorry a head of time)
but would this have worked as well?

<script type="text/javascript">
function getcharacters()
{
var len = this.length;
y=0;
for(y=1,y> len,y++)
{
x = y-1;
$variable + y + = this.substring(x,y);
}
}
</script>
__________________
"If you say something interesting, people will remember your name" ~ Anonymous


Please login or register to view this content. Registration is FREE
.asp <- Irony
Zoltar1992 is offline
Reply With Quote
View Public Profile
 
Old 03-30-2009, 11:48 AM Re: PHP Parsing; Possible? (please help)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Code:
function getChars(var s)
{
    return s.split("");
}
By the way, the PHP method that I posted is a bit redundant since the string can already be indexed as an array.
PHP Code:
$myString 'Hello World';

for(
$i 0$i strlen($myString); $i++)
{
     echo 
$myString[$i] . ' ';
}

//output
//H e l l o  W o r l d 
__________________

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

Last edited by NullPointer; 03-30-2009 at 11:50 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-30-2009, 12:08 PM Re: PHP Parsing; Possible? (please help)
Skilled Talker

Posts: 68
Name: Avi Zolty
Location: Atlanta
Trades: 0
Thanks, works great
Ahh, so i should have just gone with javascript all along *sigh*
Thanks for the help ...
but hypothetically, would my script have worken(sp. worked?)?

aaand in the return s.split case how would I put it into an array from that?
__________________
"If you say something interesting, people will remember your name" ~ Anonymous


Please login or register to view this content. Registration is FREE
.asp <- Irony

Last edited by Zoltar1992; 03-30-2009 at 12:09 PM..
Zoltar1992 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Parsing; Possible? (please help)
 

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