PDA

View Full Version : string in php?



Scaper
05-02-2010, 05:50 PM
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




//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);
#
?>

ZaSz
05-02-2010, 06:14 PM
$user = 'scaper';
or
$user = "scaper";

Scaper
05-02-2010, 06:21 PM
ohh crap 1 sec

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

under the timerunning etc it just shows as a 0

Frement
05-02-2010, 06:47 PM
//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);
#
?>

ZaSz
05-02-2010, 07:01 PM
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
05-02-2010, 08:09 PM
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:

imagettftext($im, 10, 0, 143, 167, $textcolour, $font, $user);
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:

$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";
}
}

Usage:

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

ZaSz
05-02-2010, 10:11 PM
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
05-02-2010, 10:14 PM
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
05-02-2010, 11:46 PM
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
05-03-2010, 12:09 AM
Nava, I see that the "$value > 100000 &&" is missing in yours, but how is that diffrent?

Nava2
05-03-2010, 02:31 AM
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. 

Frement
05-03-2010, 04:28 AM
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. 

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

Scaper
05-04-2010, 01:56 PM
Thanks guys espically Frement and zasz

@Frement

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

$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


//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);
?>

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
05-04-2010, 02:57 PM
Thanks guys espically Frement and zasz

@Frement

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

$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


//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);
?>

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
05-04-2010, 03:14 PM
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
05-04-2010, 03:44 PM
Heres the PHP script with my functions added:

<?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);

?>

Scaper
05-04-2010, 06:19 PM
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


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

Frement
05-04-2010, 06:25 PM
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


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

Replace with:

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

Scaper
05-04-2010, 07:24 PM
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
05-04-2010, 07:27 PM
ohh also how do imake an image like icefires sig count like stacks inmy sig pleaseWhat?

Frement
05-04-2010, 07:50 PM
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
05-04-2010, 08:02 PM
What? Explain in clear english thx! :D

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

Frement
05-04-2010, 08:06 PM
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

//$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;
}

?>
Should work, let me know if it doesnt :P

Scaper
05-04-2010, 08:34 PM
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
05-04-2010, 08:38 PM
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
05-05-2010, 02:13 PM
ok i will rar it all up can you set the mysql database up? too

Frement
05-05-2010, 02:18 PM
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
05-05-2010, 03:11 PM
here this is the current structure

Scaper
05-06-2010, 12:37 PM
have you done it yet frement i gave you my files yesterday and you havent gotten back to me