3v4l.org

run code in 300+ PHP versions simultaneously
<?php $bodycontent = "<p>We've been in business since 1998 and produced this logo design [1995] years ago.</p>\n"; $bodycontent .= "<p>We've been in business since 1998 and produced this website design [2018] years ago.</p>\n"; $bodycontent .= "<p>We've been in business since 1998 and produced this website design [2017] years ago.</p>\n"; $bodycontent .= "<p>We've been in business since 1998 and produced this website design [2016] years ago.</p>"; $lookup=['less than a','one','two','three','four','five','six','seven','eight','nine', 'ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen' ]; // extend as needed $bodycontent = preg_replace_callback('/\[(\d{4})] years ago/', function($m)use($lookup){ $diff=date('Y')-$m[1]; if(isset($lookup[$diff])){ return $lookup[$diff].' year'.($diff>1?'s':'').' ago'; }else{ return "in {$m[1]}"; // out of lookup range, use backup text } }, $bodycontent); echo $bodycontent;
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
<p>We've been in business since 1998 and produced this logo design in 1995.</p> <p>We've been in business since 1998 and produced this website design less than a year ago.</p> <p>We've been in business since 1998 and produced this website design one year ago.</p> <p>We've been in business since 1998 and produced this website design two years ago.</p>

preferences:
72.72 ms | 408 KiB | 5 Q