late night coding rules! (about strings)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

late night coding rules! (about strings)

Post by m3mn0n »

</sarcasm>

i need some n00bish help...ugh

I have a two part string.

I have an easy way to get everything before the seperator which in my case is a space. I used the strtok() function.

It worked great.

My only issue is, i have no way to get the last part of the two part string without including the first part.

example: $string = "blablablablabla heheheheehhe";

if i use the seperator " ", i get blablablablabla fine, but heheheheehhe is unaccessable alone.


The book i used to get the hang of this all didn't explain one bit how to get that last part. I can't use substr() since it requires exact string length and the first and last strings are both not always the same length.

I'm wondering if there is some easy way to do this that i have not found yet. :oops:
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

use explode() or ereg


$resultarray=explode(" ",$string);
//$resultarray[0] is string part 1
//$resultarray[1] is string part 2



if (ereg ("([a-zA-Z0-9]+) ([a-zA-Z0-9]+)", $string, $regs)) {
echo "String 1: $regs[1]; String 2: $regs[2]";
} else {
echo "Pattern not found";
}
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

*slaps forehead*

I should have thought of that one!

So there is no str* function that can do this? I wonder why the hell he didn't include explode() in his book. :?
Post Reply