PDA

View Full Version : split help.. i think?


magnus
01-27-2004, 06:12 PM
I have a variable, $threadinfo[foousers], which containts a list of users separated by spaces. (ie. $threadinfo[foousers] = "foo1 foo2 foo3").

I'm trying to add code to newreply.php that will check the current user against that list, and if a positive match is found it will return foo();

I've tried using the illegal username code, but I just can't seem to tweak it right.

Any help would be appreciated. ;)

MindTrix
01-27-2004, 10:21 PM
Wouldnt this be a job for good old Array??

NTLDR
01-27-2004, 10:25 PM
You can only return something if you areb within a function and IIRC there are none in newreply.php anyway this should do what you want:

if (in_array($bbuserinfo['username'], explode(' ', $threadinfo['foousers']))) {
foo();
exit;
}

MindTrix
01-27-2004, 10:27 PM
Whats the Explode part about?? (Sorry just never seen that before)

NTLDR
01-27-2004, 10:32 PM
Explodes all the values using ' ' (space) as the seperator into an array, for example:

$test = 'a b c d';
$array = explode(' ', $test);


$array = array('a', 'b', 'c');


The top, essentially gives you the bottom result :)

MindTrix
01-27-2004, 10:35 PM
o k

Yeah i get it :) Cheers for explaining.

magnus
01-28-2004, 12:23 AM
Woops, forgot about this.. actually, I have it all working using:


if (!empty($threadinfo['foousers']))
{
$usernames = preg_split('/( )+/', trim(strtolower($threadinfo['foousers'])), -1, PREG_SPLIT_NO_EMPTY);
foreach ($usernames AS $val)
{
if (strpos(strtolower($bbuserinfo['username']), strtolower($val)) !== false)
{
foo();
}
}
}


This is just modified code from vB's Illegalname check. :D