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;

preferences:
29.33 ms | 405 KiB | 5 Q