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.

Douglas

Recommended Answers

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

All 3 Replies

$string = 'username Membership Fee' or 'Username29473 Membership Fee';
$string = explode(' ', $string);
$username = $string[0];
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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.