Good afternoon.

What I'm trying to do is to get the username from the beginning of a field of data

example 'username Membership Fee' or 'Username29473 Membership Fee'

What I need to do is just get the 'username' or the 'Username29473' extracted as a value in a variable of it's own...

Know it has to be easy, but drawing a total blank, and working against the clock (as usual)

thanks in advance.


Recommended Answers

All 3 Replies

$string = 'username Membership Fee' or 'Username29473 Membership Fee';
$string = explode(' ', $string);
$username = $string[0];

Yep, that is it, thank you...

Always seem to draw a blank when I am in a rush.

Member Avatar

There are variations on a theme:

$string = 'username Membership Fee';
echo strtok($string, " ");

$string = 'username Membership Fee';
echo strstr($string, ' ', true);

$string = 'username Membership Fee';
echo current(explode(' ', trim($string)));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.