preg-quote

Make search in text file case-insensitive

戏子无情 提交于 2021-02-20 04:08:48
问题 I'm using the following function to search for words in a text file. The problem is that this function is case-sensitive. I don't want it to be case-sensitive! How can I make the function case-insensitive? $url = 'files/file.txt'; $thedata = file_get_contents($url); $lines = explode(PHP_EOL, $thedata); $search = 'some search words'; $pattern = preg_quote($search, '/'); $pattern = "/^.*$pattern.*\$/m"; if(preg_match_all($pattern, $thedata, $matches)) { echo implode('<br>', $matches[0]); } else

Make search in text file case-insensitive

孤街醉人 提交于 2021-02-20 04:08:01
问题 I'm using the following function to search for words in a text file. The problem is that this function is case-sensitive. I don't want it to be case-sensitive! How can I make the function case-insensitive? $url = 'files/file.txt'; $thedata = file_get_contents($url); $lines = explode(PHP_EOL, $thedata); $search = 'some search words'; $pattern = preg_quote($search, '/'); $pattern = "/^.*$pattern.*\$/m"; if(preg_match_all($pattern, $thedata, $matches)) { echo implode('<br>', $matches[0]); } else

preg_replace with preg_quote except one column

我的梦境 提交于 2019-12-20 06:43:39
问题 I'm trying to make some tricks with preg_replace used with preg_quote. I have an array of json data object and what I want to Replace all values of keys except the value of one key Below is the basic structure of the input array: $posts = [{"title":"Test owy post avela","subtitle":"test subtitle", "slug":"test owy-post-laravela-4", "created_at":"2014-11-02"}, {...} ] and I need to replace all values of tes to <span>tes</span> except from slug key's value below is the code where $posts is