note 112203 added to function.preg-replace
| From: | Dustin | Date: | Thu, 16 May 2013 11:53:50 +0000 |
| Subject: | note 112203 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194826@lists.php.net to get a copy of this message | ||
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
----
Server IP: 91.199.167.223
Probable Submitter: 212.123.196.50
----
Manual Page -- http://php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/112203
Del: integrated -- https://master.php.net/note/delete/112203/integrated
Del: useless -- https://master.php.net/note/delete/112203/useless
Del: bad code -- https://master.php.net/note/delete/112203/bad+code
Del: spam -- https://master.php.net/note/delete/112203/spam
Del: non-english -- https://master.php.net/note/delete/112203/non-english
Del: in docs -- https://master.php.net/note/delete/112203/in+docs
Del: other reasons-- https://master.php.net/note/delete/112203
Reject -- https://master.php.net/note/reject/112203
Search -- https://master.php.net/manage/user-notes.php