• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Equivalent code for XenForo

Zephyr

Well-known member
#1
Hello, what is the equivalent code for XenForo please?

PHP:
<?php
$monTableauDeCouleur = array('#FFFFFF', '#000000');
$maCouleurAuHasard = $monTableauDeCouleur[rand(0, count($monTableauDeCouleur) - 1)];
 
echo $maCouleurAuHasard;
echo 'test';
 
?>
This code shows me nothing. Thank. :)
 

Zephyr

Well-known member
#3
PHP:
<?php
$arrayColors = array('#FFFFFF', '#000000');
$randomColor = $arrayColors[rand(0, count($arrayColors) - 1)];
 
echo $randomColor;
 
?>
:p
 

James

Well-known member
#4
You need to provide more information. There's no software-specific code there at all, it's merely a case of:
a) What's it for?
b) Where is it going to be displayed?
 

Lawrence

Well-known member
#5
Your code echo's out what you are telling it to, e.g: #000000test

I take it you want to randomly change the color of the word "test"?

Code:
<?php
$monTableauDeCouleur = array('#FFFFFF', '#000000');
$maCouleurAuHasard = $monTableauDeCouleur[rand(0, count($monTableauDeCouleur) - 1)];
 
$colorOutput = '<span style="color: ' . $maCouleurAuHasard . ';">test</span>';
echo $colorOutput;
 
?>
 

cclaerhout

Well-known member
#6
If you're testing your code in Xenforo, the echo command might not be displayed. Use var_dump($le_nom_de_ta_variable) or better Zend_Debug::dump($ta_variable). If you're working with a template or a file which is using ajax to display, see the console of Firebug (Firefox). If you're testing a Javascript code (not php this time), use console.log(tavariable) then go to the Firebug console.
Bon courage !