MyBB Community Forums

Full Version: Issue with PHP and a variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Alright, I made it so that I can use PHP in templates, but I am having this issue. I want to display a user's Group ID, but here's what happens:

If I put
<?php
echo "{$mybb->user['usergroup']}";
?>
then it shows the Group ID, but get this error
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in directory/global.php(433) : eval()'d code(27) : eval()'d code on line 2

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in directory/global.php(433) : eval()'d code(27) : eval()'d code on line 2

If I make it
<?php
echo "\{$mybb->user['usergroup']\}";
?>
then the PHP errors disappear, but the variable shows
\{Array[\usergroup\]\}
instead of the Group ID.

What can I do? Or is there an alternate way? BTW, I am adding the PHP into the main header template.
How have you got to use PHP in templates - did you use a modification?

If so, you're probably best off looking into the author's support forums.

An alternative way would be do:

<?php echo "{".$mybb->user['usergroup']."}"; ?>

... but I don't think it would make much difference (that's just the way I'd code it)...

Edit: Could it be to do with the { } tags?... try removing them or changing them to specialchars...
(2008-11-09, 03:23 PM)Tom.M Wrote: [ -> ]How have you got to use PHP in templates - did you use a modification?

If so, you're probably best off looking into the author's support forums.

An alternative way would be do:

<?php echo "{".$mybb->user['usergroup']."}"; ?>
I did that and it just deleted everything after it in the templates Sad
C'mon, nobody can help me?
Just bumping it so it goes back to the top.
Ok Bump? (Hoping this works)
Well this is obviously a problem with your modification. Can you post it here? I suspect you are having problems because $templates->get() automatically backslashes double quotation marks (") so I think you should stripslashes before you eval the PHP.
You can already just use a variable in the code though, if you're not meaning to extend it futher to functions and stuff.
(2008-11-10, 07:59 PM)DennisTT Wrote: [ -> ]Well this is obviously a problem with your modification. Can you post it here? I suspect you are having problems because $templates->get() automatically backslashes double quotation marks (") so I think you should stripslashes before you eval the PHP.
This is the modification: http://community.mybboard.net/thread-318...+templates

(2008-11-10, 09:37 PM)CraKteR Wrote: [ -> ]You can already just use a variable in the code though, if you're not meaning to extend it futher to functions and stuff.

I am trying to make a PHP if else statement so that text would show if a member is in a certain group, but not in another.
Bump Sad
No Help?
$mybb->user['usergroup']

Try it without the single quotes

$mybb->user[usergroup]

Also look into the displaygroup for the user...should be

$mybb->user['displayusergroup'] or something like that. Do a print_r($mybb->user) to get all the variables available.
Pages: 1 2