note 112203 deleted from function.preg-replace by crell
| From: | crell@php.net | Date: | Fri, 01 Jul 2022 19:49:04 +0000 |
| Subject: | note 112203 deleted from function.preg-replace by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218862@lists.php.net to get a copy of this message | ||
Note Submitter: Dustin
----
Matching substrings where the match can exist at the end of the string was non-intuitive to me.
I found this because:
strtotime() interprets 'mon' as 'Monday', but Postgres uses interval types that
return short names by default, e.g. interval '1 month' returns as '1 mon'.
I used something like this:
$str = "mon month monday Mon Monday Month MONTH MON";
$strMonth = preg_replace('~(mon)([^\w]|$)~i', '$1th$2', $str);
echo "$str\n$strMonth\n";
//to output:
mon month monday Mon Monday Month MONTH MON
month month monday Month Monday Month MONTH MONth