dongwei4103 2012-05-24 09:00
浏览 61
已采纳

将此PHP转换为Actionscript?

Note: I have read https://meta.stackexchange.com/questions/128548/what-stack-overflow-is-not/129362#129362

It says "try to write the code yourself and post what you've tried when you run into problems." which is what I am doing here.

The original PHP code:

$text = "Hello world, I am rainbow text!";
$texty = '';
    $colors = array('ff00ff','ff00cc','ff0099','ff0066','ff0033','ff0000',
                    'ff3300','ff6600','ff9900','ffcc00','ffff00','ccff00',
                     '99ff00','66ff00','33ff00','00ff00','00ff33','00ff66',
                     '00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff',
                     '0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff'); 
        $i = 0;
$textlength = strlen($text);
while($i<=$textlength){
foreach($colors as $key=>$value){
    if (isset($text[$i])) {
        $texty .= "<font color=\"#".$value."\">".$text[$i]."</font>";
    }
    $i++;
}
$texty = str_replace("> <",">&nbsp;<",$texty);
echo $texty;
}

What I've butchered it down to:

var text = "Hello world, I am rainbow text!";
var texty = '';
colors = new Array

('ff00ff','ff00cc','ff0099','ff0066','ff0033','ff0000',
 'ff3300','ff6600','ff9900','ffcc00','ffff00','ccff00',
 '99ff00','66ff00','33ff00','00ff00','00ff33','00ff66',
 '00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff',
 '0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff'); 
var i = 0;

var textlength = text.length;
var key = '';
var value = '';
while(i <= textlength){
for each(colors as key=>value){
    if (text[i] != undefined) {
        texty .= "<font color=\"#" + value + "\">" + text[i] + "</font>";
    }
    i++;
}
texty.replace("> <",">&nbsp;<");
//document.write(texty);
}

I've been testing this as Javascript, which is why I have document.write commented in the code. However, I still cannot get it to work. I hate to be so vague but... can someone tell me where I screwed up?

  • 写回答

2条回答 默认 最新

  • dongniaocheng3773 2012-05-24 09:12
    关注

    Got something with your code, but didnt get what you trying to do. Check out fiddle.

    http://jsfiddle.net/ymutlu/pKCcS/

    this looks better...

    http://jsfiddle.net/pKCcS/2/

    posted code here, in case i delete fiddle link.

    var text = "Hello world, I am rainbow text!";
    var texty = '';
    colors = ['ff00ff','ff3300','ff6600','ffff66','00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff','0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff']; 
    var i = 0;
    
    
    var textlength = text.length;
    var key = '';
    var value = '';
    while(i <= textlength){
        var t = text.charAt(i);
    
        if (t!= undefined) {
            texty += "<font color=\"#" + colors[i%colors.length] + "\">" +  t + "</font>";
        i++;
    }
    }
    
    texty.replace("> <",">&nbsp;<");
    document.write(texty);
    

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。