Staredit Network

Staredit Network -> Computers and Technical -> PHP Question
Report, edit, etc...Posted by RexyRex on 2006-02-07 at 21:00:55
Or, you could try to pickup the PCRE syntax and do some advanced string manipulating.

But, um, good luck with that. mellow.gif
Report, edit, etc...Posted by Shmeeps on 2006-02-07 at 21:38:19
Well, the only thing with that is that it may pick up a copy of the string somewhere. For instance, searching for AEIOU could show up in the palette and somewhere else, like the pixel info.
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-07 at 22:46:36
could you use a substring and then replace the parts in that, then put it back into where it goes?
Report, edit, etc...Posted by RexyRex on 2006-02-08 at 23:37:45
Yeah, that's kinda what I was saying.
preg_replace("[subclass]",$var,$var2);
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-16 at 22:58:16
Instead of making a whole new topic, I decide to just add onto this one since the title will fit pretty much anything to do with PHP.

I am thinking about making something that will randomly display a quote, but since I cannot put scripts into my signature I have looked once again at PHP.
I know PHP can do randomization, and I know it can put text into images. So I would like to know how to do something that takes a random entry from an array (or some kind of list of quotes) and shoves it in an image that is used for my sig.

(Keep in mind I am still newb at PHP :P)

Edit: Maybe I should try and look a little instead of just being a lazy Farty and just posting like the n00b I am.
Report, edit, etc...Posted by RexyRex on 2006-02-17 at 16:25:53
Maybe my winamp signature will help you a bit.
Also, look up the functions array_rand(); and fread(); smile.gif
[codebox]<?php
ob_start();
header('Content-type: image/gif');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');

function color($r = 0, $g = 0, $b = 0) {
global $img;
return imagecolorallocate($img,$r,$g,$b);
}

$gif = getimagesize("winamp.gif");

$handle = fopen("info.txt","r");

$song = fread($handle,filesize("info.txt"));

$width = 4 + $gif[0] + (strlen($song) * 7) + 3;
$height = 28;

$gif_image = imagecreatefromgif("winamp.gif");
$img = imagecreatetruecolor($width,$height);
imagecopy($img,$gif_image,1,1,0,0,$gif[0],$gif[1]);

$red = color(255);
$white = color(255,255,255);

imagestring($img,3,4 + $gif[0],$height / 3.75,$song,$white);

imageline($img, 0, 0, 0, $height, $red);
imageline($img, 0, 0, $width, 0, $red);
imageline($img, 0, $height - 1, $width, $height - 1, $red);
imageline($img, $width - 1, 0, $width - 1, $height - 1, $red);

imagegif($img);
imagedestroy($img);
?>[/codebox]
Report, edit, etc...Posted by O)FaRTy1billion on 2006-02-17 at 17:28:59
In PHP do you have to use "color(255,255,255)"? Could you use 16777216 (just a number) for white? I like using just numbers for some reason tongue.gif
Report, edit, etc...Posted by Shmeeps on 2006-02-17 at 22:56:21
Yes, you have to use a RGB value.

If it helps at all, here's the code for my old quote sig, well commented, I think.

CODE
<?

//Connect to the MySQL database
require 'connect.php';

// Tell the user's browser that it is an image
header("Content-type: image/png");  

//Get all entries from database and put into an array
$query = mysql_query("SELECT * FROM `Quotes` ORDER BY RAND() LIMIT 1");
while($row = mysql_fetch_array($query, MYSQL_ASSOC))
{
$phrase = $row['LineOne'];
$phrase2 = $row['LineTwo'];
}

// load the background
$image = imagecreatefrompng("sig.png");

// define the color black (the colour of the text)
$clr_black = imagecolorallocate($image, 0, 0, 0);
   
// define the font, x_position
// how much the y_position changes (increments)
$font = 2;
$x_pos = 5;
$y_inc = 5;

//Set what line number we are writing
$line_number = 1;

// draw heading
imagestring($image, $font, $x_pos, $y_inc * $line_number, $phrase, $clr_black);
$line_number += 2;
imagestring($image, $font, $x_pos, $y_inc * $line_number, $phrase2, $clr_black);

// and now... we display the image
imagepng($image);
imagedestroy($image);
?>
Report, edit, etc...Posted by O)FaRTy1billion on 2006-03-10 at 17:24:41
w00t! It works!
Thanks everyone; and especially for shmeeps for that code to base it on, and Rexy for saying "array_rand();". (Reading PHP is no problem, as with anything. Its just I can't write it without something to start with.)

Now I need a better PHP host besides my Sister's site, and to put more stuff than just random words to test it.
Report, edit, etc...Posted by Doodle77(MM) on 2006-03-12 at 09:57:32
if you dont need huge bandwidth, then you can set up a Dynamic DNS account, only problem is you need to set up port 80 forwarded to your computer and unblock port 80 on your firewall. Its free, and you get everything you get with your computer.
Report, edit, etc...Posted by O)FaRTy1billion on 2006-03-12 at 14:09:09
My firewall is just a freeware version so I can't mess with ports, and trying to open them on my router does not do anything either.. And wouldn't I need stuff to work with the PHP?
(I just uploaded it all onto my sister's website, because I have access to it, to test it.)
Next Page (2)