LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-05-2017, 04:01 PM   #1
schnappi
Member
 
Registered: Apr 2017
Posts: 52

Rep: Reputation: 3
PHP dynamic number in HTML


Hi,

Currently use this a lot in HTML:

Code:
<?php echo date("Y") ?>
Is there a similar way to use a similar php statement to insert a dynamic number (say the number of years between 2000 and 2017)?
 
Old 09-05-2017, 04:13 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
PHP is a general purpose scripting language. You can use any valid function and equation etc to calculate any sort of number desired.

There are many tutorials and websites on php programming and creating dynamic websites and I posted a couple of links.
Are you asking how to calculate the number of years between two dates?

http://php.net/
https://www.w3schools.com/php/
 
1 members found this post helpful.
Old 09-05-2017, 04:19 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Your question can be understood more than one way. It would be helpful if you could tell us more precisely what you are trying to do, and what you mean by dynamic number in your own use context.

For example, if you really just want "the number of years between 2000 and 2017" then simply do the math and echo the result:

Code:
echo 2017-2000;
If you want each year in the range then a for loop will do it:

Code:
for($x=2000;$x<=2017;$x++)
        echo $x."\n";
How you do it depends very much on what you are trying to do.
 
Old 09-06-2017, 11:20 AM   #4
schnappi
Member
 
Registered: Apr 2017
Posts: 52

Original Poster
Rep: Reputation: 3
Thanks.

This gave what was looking for:
Code:
<?php echo date("Y")-2000 ?>
The above gives a dynamic number of years such as 17 years experience, ect.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Warning: PHP Startup: Unable to load dynamic library jojanmpaul Linux - Newbie 2 11-20-2014 12:37 AM
PHP Warning: PHP Startup: Unable to load dynamic library jojanmpaul Linux - Newbie 2 03-01-2014 05:02 AM
[SOLVED] PHP5 - Creating Dynamic Select List - HTML Ignores php code pizzipie Programming 0 09-16-2013 04:25 PM
PHP + MYSQL: Invalid parameter number: number of bound variables does not match... OrangeGrover Linux - Software 6 05-08-2013 05:36 PM
Embedded PHP in HTML- either PHP ignored or HTML broken vltreude Programming 1 12-10-2012 02:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration