Page 1 of 1

Noob Question. HTML + PHP

Posted: Tue Sep 07, 2010 12:08 pm
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--

Re: Noob Question. HTML + PHP

Posted: Tue Sep 07, 2010 12:35 pm
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)?

Re: Noob Question. HTML + PHP

Posted: Tue Sep 07, 2010 12:43 pm
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.

Re: Noob Question. HTML + PHP

Posted: Tue Sep 07, 2010 12:59 pm
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.

Re: Noob Question. HTML + PHP

Posted: Tue Sep 07, 2010 11:56 pm
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>'; }

?>

Re: Noob Question. HTML + PHP

Posted: Wed Sep 08, 2010 2:12 am
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;						
 }
} ?>