2011-08-16 39 views
0

我不確定這是否可能,但我試圖取$ css_color的值並將其設置爲div中的十六進制值。還有$ x和$ y值。抓取PHP信息並放入div內

本質上,我試圖從圖像中獲取$ x $ y信息和十六進制代碼值,並將其匹配到格式化的顏色值數組中,然後將格式爲「div」的圖像重建爲背景顏色作爲測試。我formatted_colors.js陣列var colors = []; colors["000000"] = "black"; colors["100000"] = "black";

這裏的

例子是一個片段:

<script type="text/javascript" src="jquery-1.6.2.js"></script> 
<script src="formatted_colors.js" type="text/javascript" charset="utf-8"></script> 
<script type="text/javascript"> 

//iterate through pixels and match rounded color to array in formatted_colors.js 

<div class="rounded_color" hex="<?php $css_color ?>" xy="<?php $x.$y ?>"</div> 
<div id="<?php $x.$y ?>"></div> 

$(document).ready(function() { 

    $(".rounded_color").each(function(){ 
      var google_color = getColor($(this).attr("hex")); 
      $('#'+$(this).attr("id")).html(google_color); 
      $('#'+$(this).attr("id")).css('background-color:', google_color); 
    }) 


// get name of color function from formatted_colors.js 

function getColor(target_color){ 
    if (colors[target_color] == undefined) { // not found 
     return "no match"; 
    } else { 
     return colors[target_color]; 
    } 
    } // end getColor function 


)} // end ready function 

</script> 

這裏是我的全部代碼:http://pastebin.com/A4tMsn2C

回答

1

嘗試<?php echo $x.$y ?>來代替(類似於您的其他塊)。或者,如果您已啓用短標籤<?= $x . $y ?>。您的版本只是在進行concocuation並拋出結果。你需要回應你在PHP塊中做什麼的結果。

+0

<?php echo $ x。$ y?>是更安全的賭注。短標籤是不好建議.. http://stackoverflow.com/questions/200640/are-php-short-tags-acceptable-to-use – rlemon