Heyy, need some help here.

ok, I've got my script here right.

<html>
<head><title>Display Records</title>
<style type="text/css">
td {font-family: tahoma, arial, verdana; font-size: 10pt }
</style>


</head>
<body>
<?php
$db="aseco121";
$link = mysql_connect('127.0.0.1: 3306', 'root', '******');
if (! $link)
die(mysql_error());
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT * FROM players ORDER BY Login" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";

print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){ 
print "<tr>\n";
foreach ($get_info as $field) 
print "\t<td>$field</td>\n";
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>
<br>

</body>
</html>

and it comes out with my tables okay?
bieing:
+----+--------+-------------------------+
| 76 | .enjo. | $i$0f0N$000R$ff0G |
+----+--------+-------------------------+
---- table goes on -----

and this '$i' thing is like trackmania font coosing
so $i$0f0N$000R$ff0G would turn out to be NRG (green N, Black R, Yellow G)

note that thier are tonnes of combonations i dont want to write each on out. so how would i get to remove the $ format codes and replace them with things that work in html/php?

so instead of '$F00MAXICUBE' i want MAXICUBE

colour table: http://tutorials.tm-creative.org/general_formattingtext_colours/index.php

anybody got any suggestions?

Member Avatar for diafol

Hi Maxicube - that's some interesting code on trackmania. Haven't seen that type of encoding before.

Can you give more details about how this is going to be used?


For the DB example:
The only thing I can think of is chopping up the string into bits using explode on the '$' character. You know your last chunk is the yellow, penultimate is black and the previous one is yellow. Any bits left over can be compared with a simple array to get the right format (e.g. $i%s -> <em>%s</em>).

If Just colours:
Each example uses the $ + 3 hexadecimal chars. You can use the FONT tag and add a 'color' attribute - but this is bad. A span tag with the 'color' attribute would be more acceptable, although a 'class' attribute linked to a CSS file would be really good. How you'd do the latter I'm not sure as each color would probably require its own class name - bit awkward.

So: $f00MAXICUBE turns to <span color="#ff0000">MAXICUBE</span> Basically you need to double each hex character and relpace the $ with a #, surround the text part with span tags and insert a color attribute.

Personally, I'd write a function something like this (it's a bit dirty - all the substr!):

function colorize($tmString){
   $colorhex = '#' . substr($tmString,1,1) . substr($tmString,1,1) . substr($tmString,2,1) . substr($tmString,2,1) . substr($tmString,3,1) . substr($tmString,3,1);
   $string = substr($tmString,4);
   $output = "<span color=\"{$colorhex}\">{$string}</span>";
   return $output;
}

USAGE:

$txt = "$f00MAXICUBE";
echo "I went to a bar and saw " . colorize($txt) . " drinking a soda...";

Don't know if that's any use?

Member Avatar for diafol

Thinking about it, you may be better off just placing the hex+string directly into html and using a javascript function to read the whole document (onload), find the hex codes and convert them all

Member Avatar for diafol

This is good stuff!
You'd have to check for these first, then apply the colorize() function.

$i: italic   equivalent to <em></em>
$s: shadowed                          ??
$w: wide                                  CSS class letter spacing?
$n: narrow                               as above
$m: normal                               normal what?
$g: default color                       can be set via CSS
$o: bold                                    <strong></strong>
$z: reset all                              this could be tricky
$t: Changes the text to capitals     CSS class Capitalize
$$: Writes a dollarsign

I don't know how you'd do shadowed, but most of the others can be set with CSS classes or inline html tags. You could change all of the above to span classes, e.g. <span class = "i o w">TEXT</span> for $i$o$wTEXT .

With your CSS:

i{
  font-style:italic;
}
o{
  font-weight:bold;
}
w{
  letter-spacing:2em;
}

heh, nice work sir, i tink ill post this as solved. +rep

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.