Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2004, 02:34 AM
cat cat is offline
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default php - rotating text

i've used php to rotate banners on this site -->> http://www.bmspresents.com/bms_try/index.html

i got it from here -->> http://www.automaticlabs.com/

and i'm now trying to get the same php [but adjusted] to rotate blurbs at the bottom on each page. only i cannot figure it out.

the php has been saved in the same folders as the blurbs
the blurbs are individual html files
it's linked the same as i've linked the banners which is <img src="http://www.bmspresents.com/blurbs/rotator.php" />

below are the bits in the php. i've changed pieces to reflect font colour and paragraph size [hope i'm right about the size]

ps: i am not a programmer [css is about as far as i've been able to reach], so if you start talking in programmer speak, i'll not understand it :-D

:::::

*/

    $extList = array();
    $extList['html'] = 'text/html';
    $extList['gif'] = 'image/gif';
    $extList['jpg'] = 'image/jpeg';
    $extList['jpeg'] = 'image/jpeg';
    $extList['png'] = 'image/png';


// You don't need to edit anything after this point.


// --------------------- END CONFIGURATION -----------------------

$img = null;

if (substr($folder,-1) != '/') {
    $folder = $folder.'/';
}

if (isset($_GET['img'])) {
    $imageInfo = pathinfo($_GET['img']);
    if (
        isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        file_exists( $folder.$imageInfo['basename'] )
    ) {
        $img = $folder.$imageInfo['basename'];
    }
} else {
    $fileList = array();
    $handle = opendir($folder);
    while ( false !== ( $file = readdir($handle) ) ) {
        $file_info = pathinfo($file);
        if (
            isset( $extList[ strtolower( $file_info['extension'] ) ] )
        ) {
            $fileList[] = $file;
        }
    }
    closedir($handle);

    if (count($fileList) > 0) {
        $imageNumber = time() % count($fileList);
        $img = $folder.$fileList[$imageNumber];
    }
}

if ($img!=null) {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
} else {
    if ( function_exists('imagecreate') ) {
        header ("Content-type: image/png");
        $im = @imagecreate (375, 100)
            or die ("Cannot initialize new GD image stream");
        $background_color = imagecolorallocate ($im, 255, 255, 255);
        $text_color = imagecolorallocate ($im, 55,63,71);
        imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
        imagepng ($im);
        imagedestroy($im);
    }
}

?>






 
Old December 13th, 2004, 05:15 AM
Authorized User
 
Join Date: Oct 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

Whats the problem? Are you getting an error message?

Might be because you havn't enabled GD in ur php.ini

uncomment the line which has php_gd2.dll

Many shoes,

Jamez/SiliconFuRy
 
Old December 13th, 2004, 09:49 AM
cat cat is offline
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<<Whats the problem? Are you getting an error message?

no error message. just nothing at all. if you look at the url, there's just a question mark where the blurb should be -->> http://www.bmspresents.com/bms_try/index.html

<<Might be because you havn't enabled GD in ur php.ini
uncomment the line which has php_gd2.dll

i don't have a clue what this means. as i mentioned before, i'm not a programmer.

cat




 
Old December 13th, 2004, 11:22 AM
Authorized User
 
Join Date: Oct 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

Are you admin of the server? If so, then you need to edit php.ini to enable pph_gd2.dll.

If not, and you have leased the hosting from some company, find out if they can give you access to the php.ini, or ask them if they can enable the GD image library.

Many shoes,

Jamez/SiliconFuRy
 
Old December 13th, 2004, 07:32 PM
cat cat is offline
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'll send what you've written to my host people.

i'm just wondering why it won't work for rotating text, when almost the exact php worked like a charm for rotating the banners. [just drop and go]

in the directions it says it's a piece of cake to do for a designer. no need for intervention.

thanks, cat



 
Old December 14th, 2004, 05:47 AM
Authorized User
 
Join Date: Oct 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

Ah, ive just found you're problem.

In your HTML you have done a IMG SRC to a page that loads text(that script is returning text, if you load http://www.bmspresents.com/blurbs/rotator.php directly, you get text). IMG SRC only loads files with MAPI extension of type Image.

In english, that menas that you can only load pictures with IMG SRC.

There are simpler ways in PHP to create a random text banner, if you want to know how to do this, lemme know.

Many shoes,

Jamez/SiliconFuRy
 
Old December 14th, 2004, 06:22 AM
Authorized User
 
Join Date: Oct 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

I had a spare 10mins at work this morning :D

Heres the PHP code for rotating text...

<?php

$linesfile = "lines.txt";

$lines = file_get_contents($linesfile);

$quotes = explode("\n", $lines);
$rand = rand(1,count($quotes))-1;
$quote = $quotes[$rand];
echo $quote;

?>

Have a lines.txt available in the same Directory, with each quote on a seperate line, and make sure theres no empty line on the last line.

instead of ur <IMG> tag, use this...

<iframe src="tmp/bannertest.php" frameborder=0 scrolling=0 width=100%></iframe>

obviously, change the SRC value to the rotating text script.



Many shoes,

Jamez/SiliconFuRy





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotating Picture Control Pipen VB How-To 1 April 21st, 2006 03:48 PM
Rotating Text aliddle General .NET 0 February 12th, 2005 11:52 PM
Rotating Text in Crystal Report ashish_26 Crystal Reports 0 September 29th, 2004 01:23 PM
Ch3, P.76 - text.html/text.php not working Hostile BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 May 15th, 2004 11:09 AM
Rotating images with PHP dean_custom PHP How-To 2 March 23rd, 2004 10:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.