Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6738759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:24:24+00:00 2026-05-26T11:24:24+00:00

I am sorry for posting a dodgy code! :( But I’m terrible at writing

  • 0

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>'}

 ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:24:24+00:00Added an answer on May 26, 2026 at 11:24 am

    One obvious error is you’ve forgotten to add echo statements 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.

    if(in_array($ext[1], $img))
    { echo "<div id='thejqueryslider'><div class='slider'><img src='images/work/$photo' alt='' /> </div></div>"; }
     elseif(in_array($ext[1], $vid))
     { echo "<iframe src='$photo' width='800' height='450' frameborder='0' webkitAllowFullScreen allowFullScreen></iframe>"; }
    

    EDIT: You also have an unmatched curly bracket opened after the foreach, you’ll probably want to close it after the echo statements.

    ANOTHER EDIT: You are using the variable $photo which is not defined. Did you mean $item[1]?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for posting such a lowly beginner's question, but I just still don't know
Hi Sorry for posting a big dump of code but I'm very new at
Sorry if this sounds like a really stupid question, but I need to make
EDIT: I solved it seconds after posting the question (sorry!) but can't accept an
Here is the link : www.guidegather.com (sorry, tried posting image but cannot) If you
I've just started with opengl but I ran into some strange behaviour. Below I
First I am sorry for posting code as ugly style, I didn't know the
Sorry to be posting this question. :( But I have spent almost the entire
First let me say sorry for the amount of code I'm posting below I'm
I've been posting different versions of this code all day (sorry!). I'm now trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.