FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Can't get strings to output correctly

 


PatTheGreat42
Alrighty. I have a camera watch, and I post the various camera watch pictures on the frontpage of my website, PatTheGreat.com. However, my current watch picture collection is about 10 megs, and I don't want people downloading 10 megs of stuff every time they visit ye old site.

The solution? Have random.org spit out a random sequence, and then pick the first 99 numbers. This is the easy part.

Once I get the numbers, I format them into a three-digit string so they work as URLS for the pics, and then I paste them together into a string for the URL. Here is the code (And it's not very dense because I've been working on this and am trying to figure out what's wrong):

Code:
$pic = substr("000",strlen($sequence[$i]) - 1).$sequence[$i];
$i++;
$url = "<img src=watchpictures/Pict".$pic.".JPG>";


I've got this all in a while loop that dies when $i hits 98, and $sequence is the array with the random sequence. Anyways, I figure if, for example, $sequence[$1] == 24, it should spit out "<img src=watchpictures/Pict024.JPG>"

However, when I go to the source of the produced page, I get "watchpictures/Pict656".

Any thoughts?
shamil
I didn't found any reason for false output. if $sequence[$i] == 24 then it must output Pict024.JPG as name of picture. Make sure that $sequence[$i] is really equal to 24 at time of outputing"Pict656";

I don't understand why you use random.org for random numbers not just using php's rand function. You can sue below code instead.
Code:
$MAX_RAND = 2500;
$MAX_PICT_NUM = 99;
for($i=0; $i<$MAX_PICT_NUM; $i++)
{
 $rand_str = rand(1,$MAX_RAND);
 while(strlen($rand_str) != strlen($MAX_RAND)) $rand_str = "0".$rand_str;
 echo $url = "<img src=watchpictures/Pict".$rand_str.".JPG>";
}
AftershockVibe
Oh, I see - random.org is a website. I assumed it was some sort of file you'd made.

In that case your problem is that PHP is parsing all the HTML including tags etc from random.org and not just what is visible to the reader, hence the conversion problem.

Use rand() instead.
Stubru Freak
random.org is really good if you need it to be really random and unpredictable, but that wouldn't be necessary here.
Related topics
Fortran Tutorials(77)
Visual Basic Tutorial - File I/O in VB: Text Files
[TUTOR] A Short Intro to GD
Site Nav Suggestions...
How do you show HTML/PHP code on your website?
Programming links, info, and tutorials
DVD Playback via external projector
Simple and Detailed Mail Script
Help with PhpBB
Php - Basic Encryption site
DJ Program
CSS div alignment issue, IE and FF (newbie problem)
writing COM components in Perl
Math Equation Editor and Computer Algebra for Students
The Perfect Audio Rips
DX-Blog.be - check it out ^^
Need help understanding MySQL "Resource" type retu
Mathematical breakthrough: Zero defined!
Steam - So many upgrades = Lag
PHP Test File
PHP homepage recreation problem
C++ int to char and char to int
My first PHP + mySQL page - Need feedback
Detecting accents
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.