...

View Full Version : adding in br to extrnal text file



nickweb
11-19-2003, 12:26 AM
bit of a silly one this (im re-writing it after ie decided to crash as soon as i hit post,.. man, must remeber ctrl+c next time. lol)

I have a dynamic sig ( http://www.nick-web.co.uk/sig/button1.php ), and the code for that is


<?

// Begin Random Quote 1
$delim = "\n";
$quotefile = "random_insults.txt";
// Begin.
$fp = fopen($quotefile, "r");
$contents = fread($fp, filesize($quotefile));
$quote_arr = explode($delim,$contents);
fclose($fp);
// initiate randomness
srand((double)microtime()*1000000);
// generate random quote index
$quote_index = (rand(1, sizeof($quote_arr)) - 1);
// get quote at $quote_index and return it
$herequote = $quote_arr[$quote_index];
// End Random Quote

// Begin Random Quote 2
$delim = "\n";
$quotefile1 = "random.txt";
// Begin.
$fp = fopen($quotefile1, "r");
$contents = fread($fp, filesize($quotefile1));
$quote_arr = explode($delim,$contents);
fclose($fp);
// initiate randomness
srand((double)microtime()*1000000);
// generate random quote index
$quote_index = (rand(1, sizeof($quote_arr)) - 1);
// get quote at $quote_index and return it
$herequote1 = $quote_arr[$quote_index];
// End Random Quote 2

//Begin Image
header("Content-type: image/png"); //create png headers
$string = $_GET['text'];
$remote_addr = $REMOTE_ADDR; //assing the remote_addr variable
$agent = $HTTP_USER_AGENT; //assing the user agent variable
$host = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']); //asssing the host variable
$im = imagecreatefrompng("images/button1.png"); //background image( images/button1.png)
$black = imagecolorallocate($im, 0, 0, 0); //assing colour black, 0, 0, 0, is the R, G, B values)
$blue = imagecolorallocate($im, 0, 0, 255); //assing colour black, 0, 0, 0, is the R, G, B values)
imagestring($im, 3, 0, 0, "You Host: $host", $black); //Draw in $im(the image), 3(dunno), 0(width from edge of pic), 9(height frm top), "Host: $host"(Write that text), $black (using the colour black (Assigned earlier ;) )
imagestring($im, 3, 250, 0, "Your IP address: $remote_addr", $black); //same as above
imagestring($im, 3, 0, 15, $herequote, $blue); //same again,
imagestring($im, 3, 0, 82, $herequote1, $black); //after nick-web.co.uk randquote
imagepng($im,'',100); //create the temp image
imagedestroy($im); //destroy the temp image
//End Image
?>


as u can see, it reads 2 txt files, random_insults.txt and random.txt. If u refresh the sig a couple of times ul end up oming accross aquote that runs over the image.. i.e the text is to long. Is there any way to automatically add a br after it finds a space after, say the 80th character? (so after 80 characters, it looks for a space, and when it finds one, it adds a liane break).. is this possible?

Next up, you can see it says host and then displays some weird thing about ur host.. Is there any way so that it check s for a normal hostname, i.e aol and then just displays that instead if ABAF0F0.itp.aol.com or stuff?

Thanks in advance again.. (hopefully it wont crash this time :D :D)

Nick

nickweb
11-20-2003, 11:40 PM
can anybody help with this? i have this code


<?
// Begin Random Quote 1
$delim = "\n";
$quotefile = "random_insults.txt";
// Begin.
$fp = fopen($quotefile, "r");
$contents = fread($fp, filesize($quotefile));
$quote_arr = explode($delim,$contents);
fclose($fp);
// initiate randomness
srand((double)microtime()*1000000);
// generate random quote index
$quote_index = (rand(1, sizeof($quote_arr)) - 1);
// get quote at $quote_index and return it
$herequote = $quote_arr[$quote_index];
// Begin break the string
if ( strlen($herequote) > "70" ) {
//begin search for a space
$thisstring = explode(" ",$herequote);
for($i = 0; $i < $length; $i++){
$output[$i] = $temp_output = substr($thisstring, $i, 1);
$i++;
}
$i = 70; // set the break point
$test = $output[$i]; //set up the first test
while ( $test <> " " ) { //look for a space
$i--;
$test = $output[$i]; //get the previous character in the string
}
$test = $i;
for ($i = 0; $i = $test; $i++) {
$herequote += $output[$i];
}
$herequotf = "";
for ($i = $test; $i = $length; $i++) {
$herequotf += $output[$i];
}
}
// End break the string
// End Random Quote

// Begin Random Quote 2
$delim = "\n";
$quotefile1 = "random.txt";
// Begin.
$fp = fopen($quotefile1, "r");
$contents = fread($fp, filesize($quotefile1));
$quote_arr = explode($delim,$contents);
fclose($fp);
// initiate randomness
srand((double)microtime()*1000000);
// generate random quote index
$quote_index = (rand(1, sizeof($quote_arr)) - 1);
// get quote at $quote_index and return it
$herequote1 = $quote_arr[$quote_index];
// End Random Quote 2

//Begin Image
header("Content-type: image/png"); //create png headers
$string = $_GET['text'];
$remote_addr = $REMOTE_ADDR; //assing the remote_addr variable
$agent = $HTTP_USER_AGENT; //assing the user agent variable
$host = gethostbyaddr($HTTP_SERVER_VARS['REMOTE_ADDR']); //asssing the host variable
$im = imagecreatefrompng("images/button1.png"); //background image( images/button1.png)
$black = imagecolorallocate($im, 0, 0, 0); //assing colour black, 0, 0, 0, is the R, G, B values)
$blue = imagecolorallocate($im, 0, 0, 255); //assing colour black, 0, 0, 0, is the R, G, B values)
imagestring($im, 3, 0, 0, "You Host: $host", $black); //Draw in $im(the image), 3(dunno), 0(width from edge of pic), 9(height frm top), "Host: $host"(Write that text), $black (using the colour black (Assigned earlier )
imagestring($im, 3, 250, 0, "Your IP address: $remote_addr", $black); //same as above
imagestring($im, 3, 0, 15, $herequote, $blue); //same again,
if ( $herequotf ) {
imagestring($im, 3, 0, 25, $herequote, $blue); //same again,
}
imagestring($im, 3, 0, 82, $herequote1, $black); //after nick-web.co.uk randquote
imagepng($im,'',100); //create the temp image
imagedestroy($im); //destroy the temp image
//End Image
?>


however, i keep gettin a max execution time error... any ideas whats causing this?


Thanks again, Nick



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum