Noob Question. HTML + PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Photographist
Forum Newbie
Posts: 2
Joined: Tue Sep 07, 2010 11:49 am

Noob Question. HTML + PHP

Post by Photographist »

What is the proper syntax if I want to put php inside of quotes of HTML?
I know this look REALLY REALLY horrid of a code. I am just learning.

Code: Select all

<?php
<img src="date("mdY".jpg)" alt="Yesterdays image />   
?>
If you know of any examples it would help me alot.
Would I need to make a variable and then call upon that? and what would happen if I was at the start of a month how would the previous days code come out?
Also how would I alter the date() so I could take a list

img src="date("mdY")" alt="Tuesdays Thumbnail /> </br--
img src="date("md -1 Y")" alt="Mondays Thumbnail /></br--
img src="date("md -2 Y")" alt="Sundays Thumbnail /></br--
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Noob Question. HTML + PHP

Post by social_experiment »

If the file is saved as .php you could try this

Code: Select all

<img src="<?php echo date('mdY').'jpg'; ?>" alt="Yesterdays Images" />
A question about the script : Is there an image for each day of the year or do they repeat on a weekly basis (i.e all mondays have the same image, etc)?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Noob Question. HTML + PHP

Post by social_experiment »

Code: Select all

<img src="<?php echo date('mdY').'.jpg'; ?>" alt="Yesterdays Images" />
Correction, add a period in front of the extension or the image won't display.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Photographist
Forum Newbie
Posts: 2
Joined: Tue Sep 07, 2010 11:49 am

Re: Noob Question. HTML + PHP

Post by Photographist »

Each day of the year will have a seperate thumbnail image

I am getting closer and closer.. I will post progress...

Problem before was I was trying to put HTML inside of PHP.
If I put the PHP code only where I need it....

Code: Select all

<img src=" <?php.........echo blah blah blah ?> " />  
That works MUCH better.
r3nfr3w
Forum Newbie
Posts: 3
Joined: Mon Sep 06, 2010 7:29 pm

Re: Noob Question. HTML + PHP

Post by r3nfr3w »

If I can try a logical solution to minimize code as much as possible, you should try to implement a loop to get all the day of a year. This code won't work but you can see the idea.

Hope it helps if I'm not getting your idea wrong,
R3n

Code: Select all

<?php

/*
* getDateSignature($DayNumberInYear) : will return the string you need to get the picture
* getDayOfWeek($DayNumberInYear) : will return the day of week for your alt
*/
for(int $i=0;$i<$nDaysInYear;++$i)
{ echo '<img src="'. date(getDateSignature($i)) .'.jpg" alt="'. getDayOfWeek($i) .'" /> </br>'; }

?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Noob Question. HTML + PHP

Post by social_experiment »

This function creates an image for every day that has passed in the year up to the current day. Hope it helps

Code: Select all

<?php
/**
* create images for days
*
* create an image for each of the days that has passed in 
* the current year.
*
*/
function createImagesForDays () {
 // get the value of the current day in the year
 $currentDayValue = date('z');
	
 // create a timestamp for the first day of the current
 // year. By omitting any of the arguments in the mktime()
 // function the current value is used instead
 $timeStamp = mktime(0, 0, 0, 1, 1);

 // this loop will print while the incrementor is less
 // than and equal to the value of the current day
 for ($i = 0; $i <= $currentDayValue; $i++) {
 // create the image value
   $currentImageName = date('dmY', $timeStamp);
		
  // value of each day (in seconds) because mktime() 
  // returns a Unix timestamp
  $dayValue = 86400;
		
  // image extension
  $extension = '.jpg';
	
  // create the image name
  $image = $currentImageName . $extension;
		
  // create alternate text. this is in the form xth of Month
  // i.e 7th September
  $alt = date('jS F Y', $timeStamp);
			
  // print image to browser. include your height / width
  // properties
  echo '<img src="'. $image .'" alt="'. $alt .'" /> <br />';		
			
  // increment timestamp with 86400 seconds
  $timeStamp = $timeStamp + $dayValue;						
 }
} ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply