PDA

View Full Version : PHP text fileness



nobody
May 18th, 2003, 01:47 PM
Once again, this has probably been asked numerous time before but I don't exactly know what this is called or how I would go about searching for it. So sorry for that one.

What I want to do is have all the information on one of my pages be drawn from a txt file through php. I'm doin it all in html, no flash. So if you can point me to a tutorial or just tell me the code it would be great. I'm sure its relatively easy and everything, I'm just new to all of this.
Thanks in advance

-xxviii

ahmed
May 18th, 2003, 01:51 PM
what do you mean by 'drawn'? :)

if you just wanted the text to be included in your html file from a text file, use this
<?php include 'file.txt' ?>et voila.. whatever in the text file will appear in the html.. :)


i think i missunderstood you though.. did i :q:

nobody
May 18th, 2003, 01:52 PM
no, thats probably it, i knew it was excessively simple, let me test it out real quick and I'll tell you

nobody
May 18th, 2003, 01:57 PM
yup, that was exactly what I needed
thanks a lot

can I use HTML tags in the txt file?
or if not can you direct me to a site or something that talks about formatting...

thanks a lot again

ahmed
May 18th, 2003, 01:58 PM
Yep! :)

nobody
May 18th, 2003, 02:18 PM
yup.. i figured that out hella fast, my page looks better now too, thanks a lot

ahmed
May 18th, 2003, 02:23 PM
;)

chris9902
May 18th, 2003, 02:39 PM
if i can just ask, what did this do

did you write you site in the .txt file then use


<?php include 'file.txt' ?>

to display it on your site

nobody
May 18th, 2003, 02:39 PM
ok another question.. I want to randomlly load up an image onto my site.. what I want to do is have a file such as image.txt have information like this
image 1.jpg
image 2.jpg
image 3.jpg
(that would be in proper html, thats just an example)

I then want to just have it randomly select a line and display the html code.. i know its possible because ive seen a few examples, but couldnt figure them out..
so if you could tell me how to do that as well it would be great
thanks a ton

ahmed
May 18th, 2003, 02:43 PM
the 'include' is a php function that includes any kind of files in the script.. what the script above does is merely display the contents of the textfile in the html file the script is embedded into..

nobody
May 18th, 2003, 02:44 PM
oh.. sorry, i wasnt clear
i got the other thing to work out, this is a whole different problem, i just didnt want to create a new thread

ahmed
May 18th, 2003, 02:46 PM
lol.. that was for chris :P

anyways,, this thread might help you
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=21058&highlight=%2Arandom+image%2A

nobody
May 18th, 2003, 02:49 PM
hrmm.. im still confused.. i guess ill just do javascript for now

ahmed
May 18th, 2003, 02:53 PM
ok.. what i would do is create an array will are the image files like this:
<?php
$images[0] = 'image1.php';
$images[1] = 'image2.php';
$images[2] = 'image3.php';
$images[3] = 'image4.php';
$images[4] = 'image5.php';
?>and then have this in the html:
<img src="<php? $rand = rand(0,4);
echo $images[$rand];
?>" ></img>

nobody
May 18th, 2003, 02:59 PM
thanks ahmed, but i already got it with javascript.. but I think I'll give yours a shot too to see which one i like better
thanks for bein so helpful

ahmed
May 18th, 2003, 03:01 PM
lol.. no problem ;)
for an effect like this one i would use JS, it's client side.. theres no need to get the server invloved in generating a random image you know :)

nobody
May 18th, 2003, 03:06 PM
ohh ok
i never understood client and server side but now that i think about it its pretty obvious... i guess php would be kind of overkill.. thanks again times a miilion, btw, your site with asian person looks pretty cool

ahmed
May 18th, 2003, 03:12 PM
lol :beam:..

I do what i can :P

Maxtr0sity
May 18th, 2003, 03:15 PM
*the asian person would b me...:)

nobody
May 18th, 2003, 03:17 PM
yes it would

chris9902
May 18th, 2003, 03:30 PM
random image




<script language="JavaScript">

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="r1.jpg"
myimages[2]="r2.jpg"
myimages[3]="r3.jpg"
myimages[4]="r4.jpg"
myimages[5]="r5.jpg"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
</script>

nobody
May 18th, 2003, 03:32 PM
this is actually what i used, its almost the same though


<!--
imgArray = ["image.jpg", "image2.jpg", "image3.jpg"];
ranNum = Math.floor(Math.random()*imgArray.length);
document.write("<IMG SRC='"+imgArray[ranNum]+"' BORDER='0'>");
-->

chris9902
May 18th, 2003, 06:39 PM
nice code

much smaller:thumb:

mdipi
May 19th, 2003, 03:03 PM
ahmed:

i used this code



<?php
$images[0] = 'randIMG1.jpg';
$images[1] = 'randIMG2.jpg';
$images[2] = 'randIMG3.jpg';
?>
<img src="<php? $rand = rand(0,2);
echo images[$rand];
?> "></img>



And it gave me this error:

Parse error: parse error, unexpected '[', expecting ',' or ';' in /home/mdipi/public_html/php/random.php on line 14



<img src="<php? $rand = rand(0,2);

That is line 14. i dont see anything wrong though

ahmed
May 19th, 2003, 03:05 PM
it should be

<img src="<?php $rand = rand(0,2);
echo $images[$rand];
?>"></img>

:blush:

mdipi
May 19th, 2003, 03:46 PM
lol thanks, its the little stuff that you over look eh?

ahmed
May 19th, 2003, 03:48 PM
hehe.. i always do that ;)