SRL Archive - Web Development

string in php?


Scaper

2010-05-02 13:50:34

Ok how to i dispaly the user nam,e in my dynamic sig
see under the timerunningbox etc i shows as a 0 im wondering how to do i string in php


[php]
//DECLARE VARIABLES HERE

$timeran = $row['timeran'];

$exp = $row['natsmade'];

$natsmade = $row['experience'];





//CODE

function Sec2Time($time){

if(is_numeric($time)){
#
$value = array(
#
"years" => 0, "days" => 0, "hours" => 0,
#
"minutes" => 0, "seconds" => 0,
#
);
#
if($time >= 31556926){
#
$value["years"] = floor($time/31556926);
#
$time = ($time%31556926);
#
}
#
if($time >= 86400){
#
$value["days"] = leading_zeros(floor($time/86400), 2);
#
$time = ($time%86400);
#
}
#
if($time >= 3600){
#
$value["hours"] = leading_zeros(floor($time/3600), 2);
#
$time = ($time%3600);
#
}
#
if($time >= 60){
#
$value["minutes"] = leading_zeros(floor($time/60), 2);
#
$time = ($time%60);
#
}
#
$value["seconds"] = leading_zeros(floor($time), 2);
#
return (array) $value;
#
}else{
#
return (bool) FALSE;
#
}
#
}
#

#
function leading_zeros($value, $places){
#
// Function written by Marcus L. Griswold (vujsa)
#
// Can be found at http://www.handyphp.com
#
// Do not remove this header!
#

#
if(is_numeric($value)){
#
$leading = "";
#
for($x = 1; $x <= $places; $x++){
#
$ceiling = pow(10, $x);
#
if($value < $ceiling){
#
$zeros = $places - $x;
#
for($y = 1; $y <= $zeros; $y++){
#
$leading .= "0";
#
}
#
$x = $places + 1;
#
}
#
}
#
$output = $leading . $value;
#
}
#
else{
#
$output = $value;
#
}
#
return $output;
#
}
#

#
$timearray = Sec2Time($timeran);
#
$timestring = $timearray["days"] . ":" . $timearray["hours"] . ":" . $timearray["minutes"] . ":" . $timearray["seconds"];
#

#
header("Content-type: image/png");
#
$im = imagecreatefrompng("picture.png");
#

#
$textcolour = imagecolorallocate($im, 255, 255, 255);
#
putenv('GDFONTPATH=' . realpath('.'));
#
$font = 'font.ttf';
#
imagettftext($im, 12, 0, 170, 82, $textcolour, $font, $timestring);
#
imagettftext($im, 12, 0, 170, 110, $textcolour, $font, number_format($exp));
#
imagettftext($im, 12, 0, 170, 136, $textcolour, $font, number_format($natsmade));
#
imagettftext($im, 10, 0, 143, 167, $textcolour, $font, number_format($user));
#

#
imagepng($im);
#
imagedestroy($im);
#
?>[/php]

ZaSz

2010-05-02 14:14:59

$user = 'scaper';
or
$user = "scaper";

Scaper

2010-05-02 14:21:57

ohh crap 1 sec

http://scaper.php0h.com/sig/sig1.php?user=

under the timerunning etc it just shows as a 0

Frement

2010-05-02 14:47:44

[PHP]//DECLARE VARIABLES HERE

$timeran = $row['timeran'];

$exp = $row['natsmade'];

$natsmade = $row['experience'];

$user = "Scaper";




//CODE

function Sec2Time($time){

if(is_numeric($time)){
#
$value = array(
#
"years" => 0, "days" => 0, "hours" => 0,
#
"minutes" => 0, "seconds" => 0,
#
);
#
if($time >= 31556926){
#
$value["years"] = floor($time/31556926);
#
$time = ($time%31556926);
#
}
#
if($time >= 86400){
#
$value["days"] = leading_zeros(floor($time/86400), 2);
#
$time = ($time%86400);
#
}
#
if($time >= 3600){
#
$value["hours"] = leading_zeros(floor($time/3600), 2);
#
$time = ($time%3600);
#
}
#
if($time >= 60){
#
$value["minutes"] = leading_zeros(floor($time/60), 2);
#
$time = ($time%60);
#
}
#
$value["seconds"] = leading_zeros(floor($time), 2);
#
return (array) $value;
#
}else{
#
return (bool) FALSE;
#
}
#
}
#

#
function leading_zeros($value, $places){
#
// Function written by Marcus L. Griswold (vujsa)
#
// Can be found at http://www.handyphp.com
#
// Do not remove this header!
#

#
if(is_numeric($value)){
#
$leading = "";
#
for($x = 1; $x <= $places; $x++){
#
$ceiling = pow(10, $x);
#
if($value < $ceiling){
#
$zeros = $places - $x;
#
for($y = 1; $y <= $zeros; $y++){
#
$leading .= "0";
#
}
#
$x = $places + 1;
#
}
#
}
#
$output = $leading . $value;
#
}
#
else{
#
$output = $value;
#
}
#
return $output;
#
}
#

#
$timearray = Sec2Time($timeran);
#
$timestring = $timearray["days"] . ":" . $timearray["hours"] . ":" . $timearray["minutes"] . ":" . $timearray["seconds"];
#

#
header("Content-type: image/png");
#
$im = imagecreatefrompng("picture.png");
#

#
$textcolour = imagecolorallocate($im, 255, 255, 255);
#
putenv('GDFONTPATH=' . realpath('.'));
#
$font = 'font.ttf';
#
imagettftext($im, 12, 0, 170, 82, $textcolour, $font, $timestring);
#
imagettftext($im, 12, 0, 170, 110, $textcolour, $font, number_format($exp));
#
imagettftext($im, 12, 0, 170, 136, $textcolour, $font, number_format($natsmade));
#
imagettftext($im, 10, 0, 143, 167, $textcolour, $font, $user);
#

#
imagepng($im);
#
imagedestroy($im);
#
?> [/PHP]

ZaSz

2010-05-02 15:01:04

Instead of what frem did, replace $user = "scaper" in line 4 with $user = $_REQUEST['user'];

That way you can do http://scaper.php0h.com/sig/sig1.php?user=asjd

Frement

2010-05-02 16:09:00

From: ZaSz
Instead of what frem did, replace $user = "scaper" in line 4 with $user = $_REQUEST['user'];

That way you can do http://scaper.php0h.com/sig/sig1.php?user=asjd


I also changed the line:
[PHP]imagettftext($im, 10, 0, 143, 167, $textcolour, $font, $user);[/PHP]
to that because otherwise the number_format() would have replaced the string with 0.

I also have some functions that you could be interested in:
[PHP]$color["yellow"] = imagecolorallocate( $img, 255, 255, 0 );
$color["white"] = imagecolorallocate( $img, 255, 255, 255 );
$color["green"] = imagecolorallocate( $img, 0, 255, 128 );

function imagettftextshadow( $image, $size, $angle, $x, $y, $color, $fontfile, $text ) {
imagettftext( $image, $size, $angle, $x + 1, $y + 1, imagecolorallocate( $image, 0, 0, 0 ), $fontfile, $text );
imagettftext( $image, $size, $angle, $x, $y, $color, $fontfile, $text );
}

function rs_color( $value ) {
if ( $value < 100000 ) {
return "yellow";
} elseif ( $value > 100000 && $value < 10000000 ) {
return "white";
} else {
return "green";
}
}

function rs_value( $value ) {
if ( $value < 100000 ) {
return $value;
} elseif ( $value > 100000 && $value < 10000000 ) {
return substr( $value, 0, strlen( $value ) - 3 ) . "K";
} else {
return substr( $value, 0, strlen( $value ) - 6 ) . "M";
}
}[/PHP]

Usage:
[PHP]imagettftextshadow( $img, 12, 0.0, 175, 95, $color[rs_color( $levels )], $font, rs_value( $levels ) );[/PHP]

ZaSz

2010-05-02 18:11:19

No, i was saying line 4, you declared the user as scaper, I just said change that to what I said to make it dynamic.

Frement

2010-05-02 18:14:49

From: ZaSz
No, i was saying line 4, you declared the user as scaper, I just said change that to what I said to make it dynamic.


Yes i know, but i also stated what else i changed.

Nava2

2010-05-02 19:46:31

Frement:
function rs_color( $value ) { 
if ( $value < 100000 ) {
return "yellow";
} elseif ( $value < 10000000 ) {
return "white";
} else {
return "green";
}
}

function rs_value( $value ) {
if ( $value < 100000 ) {
return $value;
} elseif ( $value < 10000000 ) {
return substr( $value, 0, strlen( $value ) - 3 ) . "K";
} else {
return substr( $value, 0, strlen( $value ) - 6 ) . "M";
}
}

Just made it work like scape actually does it ;)

MylesMadness

2010-05-02 20:09:09

Nava, I see that the "$value > 100000 &&" is missing in yours, but how is that diffrent?

Nava2

2010-05-02 22:31:29

From: MylesMadness
Nava, I see that the "$value > 100000 &&" is missing in yours, but how is that diffrent?


If the value is exactly 10000, it will be displayed as cyan/green like M are since it was checking only if > but not >=, by removing it, it will be the correct colour if >= since if it was less it'd be encompassed by the previous statement.

Makes it faster too. &#58389;

Frement

2010-05-03 00:28:46

From: Nava2
If the value is exactly 10000, it will be displayed as cyan/green like M are since it was checking only if > but not >=, by removing it, it will be the correct colour if >= since if it was less it'd be encompassed by the previous statement.

Makes it faster too. &#58389;


Well, i dont think there will be any exact numbers, and the speed gained from it is not significant.

Scaper

2010-05-04 09:56:30

Thanks guys espically Frement and zasz

@Frement
[php]imagettftextshadow( $img, 12, 0.0, 175, 95, $color[rs_color( $levels )], $font, rs_value( $levels ) ); [/php]

$levels

i dont have anything named levels unless you meen the $exp $natsmade?

here is what i have now, also yes i didnt just want it to dispaly my username as i have it connecting to a mysql database

[php]//DECLARE VARIABLES HERE
$timeran = $row['timeran'];
$exp = $row['natsmade'];
$natsmade = $row['experience'];
$user = $_REQUEST['user'];


//CODE
function Sec2Time($time){
if(is_numeric($time)){
$value = array(
"years" => 0, "days" => 0, "hours" => 0,
"minutes" => 0, "seconds" => 0,
);
if($time >= 31556926){
$value["years"] = floor($time/31556926);
$time = ($time%31556926);
}
if($time >= 86400){
$value["days"] = leading_zeros(floor($time/86400), 2);
$time = ($time%86400);
}
if($time >= 3600){
$value["hours"] = leading_zeros(floor($time/3600), 2);
$time = ($time%3600);
}
if($time >= 60){
$value["minutes"] = leading_zeros(floor($time/60), 2);
$time = ($time%60);
}
$value["seconds"] = leading_zeros(floor($time), 2);
return (array) $value;
}else{
return (bool) FALSE;
}
}

function leading_zeros($value, $places){
// Function written by Marcus L. Griswold (vujsa)
// Can be found at http://www.handyphp.com
// Do not remove this header!

if(is_numeric($value)){
$leading = "";
for($x = 1; $x <= $places; $x++){
$ceiling = pow(10, $x);
if($value < $ceiling){
$zeros = $places - $x;
for($y = 1; $y <= $zeros; $y++){
$leading .= "0";
}
$x = $places + 1;
}
}
$output = $leading . $value;
}
else{
$output = $value;
}
return $output;
}

function rs_color( $value ) {
if ( $value < 100000 ) {
return "yellow";
} elseif ( $value < 10000000 ) {
return "white";
} else {
return "green";
}
}

function rs_value( $value ) {
if ( $value < 100000 ) {
return $value;
} elseif ( $value < 10000000 ) {
return substr( $value, 0, strlen( $value ) - 3 ) . "K";
} else {
return substr( $value, 0, strlen( $value ) - 6 ) . "M";
}
}

$timearray = Sec2Time($timeran);
$timestring = $timearray["days"] . ":" . $timearray["hours"] . ":" . $timearray["minutes"] . ":" . $timearray["seconds"];

header("Content-type: image/png");
$im = imagecreatefrompng("picture.png");

$textcolour = imagecolorallocate($im, 255, 255, 255);
$textcolour1 = imagecolorallocate($im, 255, 0, 0);
$color["yellow"] = imagecolorallocate( $img, 255, 255, 0 );
$color["white"] = imagecolorallocate( $img, 255, 255, 255 );
$color["green"] = imagecolorallocate( $img, 0, 255, 128 );

putenv('GDFONTPATH=' . realpath('.'));
$font = 'font.ttf';
imagettftext($im, 12, 0, 170, 82, $textcolour, $font, $timestring);
imagettftext($im, 12, 0.0, 170, 110, $textcolour, $font, number_format($exp));
imagettftext($im, 12, 0.0, 170, 136, $textcolour, $font, number_format($natsmade));
imagettftext($im, 10, 0, 143, 167, $textcolour1, $font, $user);

imagepng($im);
imagedestroy($im);
?>[/php]

i would love to use them functions you posted but im unsure on how to add them im a total php noob and have gotten this far with trial and error and tbh my head hurts alot lol

thanks guys <3

edit:

Also is there away i can make a font the $user variable Bold in php or would i have to download a totaly diffrent font?

Frement

2010-05-04 10:57:14

From: Scaper
Thanks guys espically Frement and zasz

@Frement
[php]imagettftextshadow( $img, 12, 0.0, 175, 95, $color[rs_color( $levels )], $font, rs_value( $levels ) ); [/php]

$levels

i dont have anything named levels unless you meen the $exp $natsmade?

here is what i have now, also yes i didnt just want it to dispaly my username as i have it connecting to a mysql database

[php]//DECLARE VARIABLES HERE
$timeran = $row['timeran'];
$exp = $row['natsmade'];
$natsmade = $row['experience'];
$user = $_REQUEST['user'];


//CODE
function Sec2Time($time){
if(is_numeric($time)){
$value = array(
"years" => 0, "days" => 0, "hours" => 0,
"minutes" => 0, "seconds" => 0,
);
if($time >= 31556926){
$value["years"] = floor($time/31556926);
$time = ($time%31556926);
}
if($time >= 86400){
$value["days"] = leading_zeros(floor($time/86400), 2);
$time = ($time%86400);
}
if($time >= 3600){
$value["hours"] = leading_zeros(floor($time/3600), 2);
$time = ($time%3600);
}
if($time >= 60){
$value["minutes"] = leading_zeros(floor($time/60), 2);
$time = ($time%60);
}
$value["seconds"] = leading_zeros(floor($time), 2);
return (array) $value;
}else{
return (bool) FALSE;
}
}

function leading_zeros($value, $places){
// Function written by Marcus L. Griswold (vujsa)
// Can be found at http://www.handyphp.com
// Do not remove this header!

if(is_numeric($value)){
$leading = "";
for($x = 1; $x <= $places; $x++){
$ceiling = pow(10, $x);
if($value < $ceiling){
$zeros = $places - $x;
for($y = 1; $y <= $zeros; $y++){
$leading .= "0";
}
$x = $places + 1;
}
}
$output = $leading . $value;
}
else{
$output = $value;
}
return $output;
}

function rs_color( $value ) {
if ( $value < 100000 ) {
return "yellow";
} elseif ( $value < 10000000 ) {
return "white";
} else {
return "green";
}
}

function rs_value( $value ) {
if ( $value < 100000 ) {
return $value;
} elseif ( $value < 10000000 ) {
return substr( $value, 0, strlen( $value ) - 3 ) . "K";
} else {
return substr( $value, 0, strlen( $value ) - 6 ) . "M";
}
}

$timearray = Sec2Time($timeran);
$timestring = $timearray["days"] . ":" . $timearray["hours"] . ":" . $timearray["minutes"] . ":" . $timearray["seconds"];

header("Content-type: image/png");
$im = imagecreatefrompng("picture.png");

$textcolour = imagecolorallocate($im, 255, 255, 255);
$textcolour1 = imagecolorallocate($im, 255, 0, 0);
$color["yellow"] = imagecolorallocate( $img, 255, 255, 0 );
$color["white"] = imagecolorallocate( $img, 255, 255, 255 );
$color["green"] = imagecolorallocate( $img, 0, 255, 128 );

putenv('GDFONTPATH=' . realpath('.'));
$font = 'font.ttf';
imagettftext($im, 12, 0, 170, 82, $textcolour, $font, $timestring);
imagettftext($im, 12, 0.0, 170, 110, $textcolour, $font, number_format($exp));
imagettftext($im, 12, 0.0, 170, 136, $textcolour, $font, number_format($natsmade));
imagettftext($im, 10, 0, 143, 167, $textcolour1, $font, $user);

imagepng($im);
imagedestroy($im);
?>[/php]

i would love to use them functions you posted but im unsure on how to add them im a total php noob and have gotten this far with trial and error and tbh my head hurts alot lol

thanks guys <3

edit:

Also is there away i can make a font the $user variable Bold in php or would i have to download a totaly diffrent font?


Ill edit that script in a min :)

Nava2

2010-05-04 11:14:36

From: Frement
Well, i dont think there will be any exact numbers, and the speed gained from it is not significant.


Its true, but just pointing it out haha, it would only last for a short time in this context, still.

My philosophy, if there is a bug fix it.

Frement

2010-05-04 11:44:47

Heres the PHP script with my functions added:
[PHP]<?php

//DECLARE VARIABLES HERE
$timeran = $row['timeran'];
$exp = $row['natsmade'];
$natsmade = $row['experience'];
$user = $_REQUEST['user'];


//CODE
function Sec2Time($time){
if(is_numeric($time)){
$value = array(
"years" => 0, "days" => 0, "hours" => 0,
"minutes" => 0, "seconds" => 0,
);
if($time >= 31556926){
$value["years"] = floor($time/31556926);
$time = ($time%31556926);
}
if($time >= 86400){
$value["days"] = leading_zeros(floor($time/86400), 2);
$time = ($time%86400);
}
if($time >= 3600){
$value["hours"] = leading_zeros(floor($time/3600), 2);
$time = ($time%3600);
}
if($time >= 60){
$value["minutes"] = leading_zeros(floor($time/60), 2);
$time = ($time%60);
}
$value["seconds"] = leading_zeros(floor($time), 2);
return (array) $value;
}else{
return (bool) FALSE;
}
}

function leading_zeros($value, $places){
// Function written by Marcus L. Griswold (vujsa)
// Can be found at http://www.handyphp.com
// Do not remove this header!

if(is_numeric($value)){
$leading = "";
for($x = 1; $x <= $places; $x++){
$ceiling = pow(10, $x);
if($value < $ceiling){
$zeros = $places - $x;
for($y = 1; $y <= $zeros; $y++){
$leading .= "0";
}
$x = $places + 1;
}
}
$output = $leading . $value;
}
else{
$output = $value;
}
return $output;
}

function rs_color( $value ) {
if ( $value < 100000 ) {
return "yellow";
} elseif ( $value < 10000000 ) {
return "white";
} else {
return "green";
}
}

function rs_value( $value ) {
if ( $value < 100000 ) {
return $value;
} elseif ( $value < 10000000 ) {
return substr( $value, 0, strlen( $value ) - 3 ) . "K";
} else {
return substr( $value, 0, strlen( $value ) - 6 ) . "M";
}
}

$timearray = Sec2Time($timeran);
$timestring = $timearray["days"] . ":" . $timearray["hours"] . ":" . $timearray["minutes"] . ":" . $timearray["seconds"];

header("Content-type: image/png");
$im = imagecreatefrompng("picture.png");

$textcolour = imagecolorallocate($im, 255, 255, 255);
$textcolour1 = imagecolorallocate($im, 255, 0, 0);
$color["yellow"] = imagecolorallocate( $img, 255, 255, 0 );
$color["white"] = imagecolorallocate( $img, 255, 255, 255 );
$color["green"] = imagecolorallocate( $img, 0, 255, 128 );

putenv('GDFONTPATH=' . realpath('.'));
$font = 'font.ttf';
imagettftext($im, 12, 0, 170, 82, $textcolour, $font, $timestring);
imagettftext($im, 12, 0.0, 170, 110, $color[rs_color($exp)], $font, rs_value(number_format($exp)));
imagettftext($im, 12, 0.0, 170, 136, $color[rs_color($natsmade)], $font, rs_value(number_format($natsmade)));
imagettftext($im, 10, 0, 143, 167, $textcolour1, $font, $user);

imagepng($im);
imagedestroy($im);

?> [/PHP]

Scaper

2010-05-04 14:19:15

when i save that it says

The image &#8220;http://scaper.herobo.com/sig/sig1.php?user=Total” cannot be displayed, because it contains errors.

its to do with this as when i take it out it works again

[php]$color["yellow"] = imagecolorallocate( $img, 255, 255, 0 );
$color["white"] = imagecolorallocate( $img, 255, 255, 255 );
$color["green"] = imagecolorallocate( $img, 0, 255, 128 ); [/php]

Frement

2010-05-04 14:25:16

From: Scaper
when i save that it says

The image “http://scaper.herobo.com/sig/sig1.php?user=Total” cannot be displayed, because it contains errors.

its to do with this as when i take it out it works again

[php]$color["yellow"] = imagecolorallocate( $img, 255, 255, 0 );
$color["white"] = imagecolorallocate( $img, 255, 255, 255 );
$color["green"] = imagecolorallocate( $img, 0, 255, 128 ); [/php]


Replace with:
[php]$color["yellow"] = imagecolorallocate( $im, 255, 255, 0 );
$color["white"] = imagecolorallocate( $im, 255, 255, 255 );
$color["green"] = imagecolorallocate( $im, 0, 255, 128 ); [/php]

Scaper

2010-05-04 15:24:39

hurrr derr why didnt i see that lol $im && $img thanks

hmmdo you know a good free host that doesnt send the data to there server before updating my mysql database also php0h reset it too after a day or 2 imcurrently with 000webhost but still no luck there

http://scaper.herobo.com/sig/sig1.php?user=NEW_TOTAL


edit

ohh also how do imake an image like icefires sig count like stacks inmy sig please

MylesMadness

2010-05-04 15:27:36

From: Scaper
ohh also how do imake an image like icefires sig count like stacks inmy sig please
What?

Frement

2010-05-04 15:50:10

From: Scaper
hurrr derr why didnt i see that lol $im && $img thanks

hmmdo you know a good free host that doesnt send the data to there server before updating my mysql database also php0h reset it too after a day or 2 imcurrently with 000webhost but still no luck there

http://scaper.herobo.com/sig/sig1.php?user=NEW_TOTAL


edit

ohh also how do imake an image like icefires sig count like stacks inmy sig please


What? Explain in clear english thx! :D

Timer

2010-05-04 16:02:46

From: Frement
What? Explain in clear english thx! :D


He wants item images with amounts.. Like stackable inventory items.

Frement

2010-05-04 16:06:31

Well, you can download RS font from this url: http://www.frement.net/srl/coh3n/rs.ttf
Then just make background image with the icons u want, put the text on the correct positions. I think i have align right function somewhere, takes a few mins to search :)

[PHP]<?php

//$x = position from right to left.
//$y = position from top to bottom / bottom to top (cant remember).
//$len = length of image.
//$font = font you use.
//$size = font size you use.
//$string = the text you are aligning.
function align_right($x, $y, $len, $font, $size, $string) {
$bbox = imageftbbox($size, 0, $font, $string);
$posx = ($len - $bbox[2]) - $x;
$posy = $y;
}

?>[/PHP]
Should work, let me know if it doesnt :P

Scaper

2010-05-04 16:34:02

Also do you know a free host thatdoes not send the data to them before sending it on to my mysql database and also one that doesnt reset it after 24 hours?

Frement

2010-05-04 16:38:54

From: Scaper
Also do you know a free host thatdoes not send the data to them before sending it on to my mysql database and also one that doesnt reset it after 24 hours?


Well, finish whatever you are doing and send it to me :) I can put it in a new folder on my server.

Scaper

2010-05-05 10:13:48

ok i will rar it all up can you set the mysql database up? too

Frement

2010-05-05 10:18:24

From: Scaper
ok i will rar it all up can you set the mysql database up? too


Yes, PM it to me when ur done, just tell me what tables you need it to have etc.

Scaper

2010-05-05 11:11:15

here this is the current structure

Scaper

2010-05-06 08:37:16

have you done it yet frement i gave you my files yesterday and you havent gotten back to me