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 494781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:31:51+00:00 2026-05-13T05:31:51+00:00

So i wanna do something like this in php. If i have a year

  • 0

So i wanna do something like this in php. If i have a year in brackets [1995] I want it to convert it to the the difference of the current year to 1995.

Something like “It’s been [1995] years since something happened.”

so with it being 2009, it’d say

“It’s been 14 years since something happened.”

Obviously the subtracting part would be pretty easy, but I can’t figure out how I’d write this so that i can put any number in brackets and the php would output the difference. I’m using this for a calendar, where dozens of dates stay the same each year, just want to note the difference.

I wanna use something like

preg_replace(array_keys($bbcode), array_values($bbcode), $events)

$bbcode array already has some items like this

"/\[url\=(.*?)\](.*?)\[\/url\]/is" => "<a href='$1' target='_blank'>$2</a>",
  • 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-13T05:31:51+00:00Added an answer on May 13, 2026 at 5:31 am

    Try something like this

    <?php
    $str = "It's been [1995] years sice something...";
    
    $regexp = '/\[(\d+)\]/e';
    $replace = 'date("Y", time()) - $1';
    
    echo preg_replace($regexp, $replace, $str);
    ?>
    

    The e modifier on the regex makes the replace string execute as PHP, rather than a simple string.

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

Sidebar

Related Questions

I wanna do something like this. I know it’s wrong: var a = from
I wanna do something like this: List<string> list = new List<string>(); ... put some
I wanna do something like this: insert into TableA (val1,val2) values (value,(select top 1
how to loop over all tags in a xml i have a php that
I have a complex algorithm that I try to code in PHP but it's
I am developing a website using PHP and Apache. I wanna turn my URLs
So, it's been about 3 years since I wrote and went live with my
I'm using mod rewrite to access my PHP files in the root directory of
I'm making a social gaming network, for learning but mostly because php is alot

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.