I am sorry for posting a dodgy code! 🙁 But I’m terrible at writing PHP (just started learning) and I certainly need to study it more. But for the moment, I really need this script working so I can showcase my artwork. 🙂 I was wondering if someone would be able to help correct it?
Basically I am getting image file names from a .txt file. The txt file is set up like this:
1|imagefilename1.jpg
2|imagefilename2.jpg
The idea of the code below is to change an element depending on the file. For example, if the file is a .mov file, it will load a video player (the videos stream from vimeo). And if it’s an image file, it will have a slideshow.
<?php
$photos=file("photos.txt");
$img = array('jpg', 'png', 'gif');
$vid = array('swf', 'mp4', 'mov', 'mpg', 'flv');
foreach($photos as $image){
$item=explode("|",$image);
$ext = explode(".", $image);
if(in_array($ext[1], $img))
{'<div id='thejqueryslider'><div class='slider'><img src='images/work/$photo' alt='' /> </div></div>'}
elseif(in_array($ext[1], $vid))
{'<iframe src='$photo' width='800' height='450' frameborder='0' webkitAllowFullScreen allowFullScreen></iframe>'}
?>
One obvious error is you’ve forgotten to add
echostatements where you want to output stuff. You should also use double quotes instead of single ones around the HTML you’re outputting, otherwise the single quotes inside it terminate the string and cause syntax errors. Finish that with semicolons at the end of the echo statements and your code should work.EDIT: You also have an unmatched curly bracket opened after the
foreach, you’ll probably want to close it after theechostatements.ANOTHER EDIT: You are using the variable
$photowhich is not defined. Did you mean$item[1]?