Paul on Nostr: Does anyone know if there's a way to do case-insensitive search + replace in PHP, but ...
Does anyone know if there's a way to do case-insensitive search + replace in PHP, but retain the original case, for highlighting search keywords?
For example, if I want to make the search results bold, searching for 'paul' in 'Paul Waring' should return:
<b>Paul</b> Waring
and not:
<b>paul</b> Waring
str_ireplace does nearly everything I need, but doesn't retain the original case. Maybe preg_replace with capture groups?
#php
Published at
2024-08-22 13:15:08Event JSON
{
"id": "f5a1a9ec2dd8d16d988990be5d49a8a2f71eb6aef3d886ba411e82352a7ce2d3",
"pubkey": "cd1235fa453225b15d2633014c95ac79d7f388669e8a81580ec991b915ff88c8",
"created_at": 1724332508,
"kind": 1,
"tags": [
[
"t",
"php"
],
[
"proxy",
"https://fosstodon.org/@pwaring/113005855253110897",
"web"
],
[
"proxy",
"https://fosstodon.org/users/pwaring/statuses/113005855253110897",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://fosstodon.org/users/pwaring/statuses/113005855253110897",
"pink.momostr"
],
[
"-"
]
],
"content": "Does anyone know if there's a way to do case-insensitive search + replace in PHP, but retain the original case, for highlighting search keywords?\n\nFor example, if I want to make the search results bold, searching for 'paul' in 'Paul Waring' should return:\n\n\u003cb\u003ePaul\u003c/b\u003e Waring\n\nand not:\n\n\u003cb\u003epaul\u003c/b\u003e Waring\n\nstr_ireplace does nearly everything I need, but doesn't retain the original case. Maybe preg_replace with capture groups?\n\n#php",
"sig": "f1257ffd8a152255d8e1a66e9d3ce55a5943a86666bde349dc11bf8484e6ffeb26e725348e305ae22097b81c8e67a426613e680666e9ef9e6884fae2104cee96"
}