2011-09-18

Share code in blooger with style

this is an update from previous post (I type using Indonesia Languages). The script I made to make my code able to share to anyone and anywhere! The script I share not always php code, but basic code etc.

Some code can't separated like I use to type in php. Example like <? $s="this is my code blabla"; ?> let's say bla-bla think are make 2 line.. For sake of easy to view. I separated using enter but in basic, separated using enter can't make problem.

Actualy there is a solution to avoid it. Today script are to make reader easy to understand the code..If you read the 2nd line (actualy that the 4th).. You will notice how long I type the textarea. in fact I was to make you understand that <textarea> .... is one line.. I able to separated the text area soo you able to understand the code.  And for the beauty of code, I type the textarea like below

<form method="post"> 
<textarea name="myCode"
style="width:440px; height:200px"
rows="15" cols="80"></textarea>
 
<br><input type=submit value='save' /> 
</form> 
<?php 
if($_POST) 
{ 
$s=$_POST[myCode]; 
$a=explode("\n",$s); 
$txt.="\n<table cellspacing='0' cellpadding='0' ><tbody>"; 
foreach($a as $val) 
{ 
$a1=explode("\t",rtrim($val)); 
$a2[]=array(count($a1),trim(htmlentities($val))); 
$max<count($a1)?$max=count($a1):$dim=1; 
} 
$txt.="<tr>"; 
for($i=0;$i<$max;$i++)$txt.="<td width=30px> &nbsp;</td>"; 
//$txt.="<td>&nbsp;</td>"; 
$txt.="</tr>"; 
$txt.="<tr bgcolor='blue'>"; 
$txt.="<td height=1px width=500px colspan='$max'>&nbsp;</td>"; 
$txt.="</tr>"; 
//================== 
$i2=0; 
for($i=0;$i<count($a2);$i++) 
{ 
$i2++; 
switch($i2%3) 
{ 
case 0: $bg="lightblue"; break; 
case 1: $bg="lightgreen"; break; 
default: $bg="#BEFEFA"; 
} 
$txt.="\n<tr bgcolor='$bg'>"; 
//my plan is to put number in here.. 
$n=$a2[$i][0]-1; 
if($n>0) 
{ 
for($i3=0;$i3<$n;$i3++){ 
$txt.="<td>\t&nbsp;</td>"; 
if($i3>100) die($txt); 
} 
} 
$n=$max-$a2[$i][0]+1; 
$txt.="\n\t<td colspan=$n align=left>"; 
$txt.='<span style="font-family: \'courier new\', courier;">'; 
$txt.=$a2[$i][1]."</span>&nbsp;</td>"; 
$txt.="</tr>"; 
} 
//=================== 
$txt.="\n</tbody></table>"; 
?><textarea name="text" style="width:440px; height:200px" rows="15" 
cols="80"><?=htmlentities($txt);?></textarea> 
<? 
echo $txt; 
} 

Tidak ada komentar: