preg-match-all

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

Parse parameters and values of smarty-like string in PHP

╄→гoц情女王★ 提交于 2021-02-05 08:00:48
问题 I'm trying to create simmiliar parser like smarty. For very small parts of code, and don't want to implement huge smarty-like parser. What I came up with is: (?:([a-zA-Z0-9]+)=(?:([^\v '"]+)|"(.*?)"|'(.*?)')|([a-zA-Z0-9]+)) On https://regex101.com/r/l5FI5f/2/ it looks fine. Every match is either 1 or 2 entries + full match. When I copy PHP code, things look different... array (size=5) 0 => string 'xddss='asdasda'' (length=15) 1 => string 'xddss' (length=5) 2 => string '' (length=0) 3 =>

get image url from array

不羁岁月 提交于 2021-01-29 05:31:03
问题 I want to get image url from array. $img_link = "http://testserver1.com:8080/test%20messages%20and%20so%20on<br /><br /><div style="text-align: center"><img width="396" height="342" src="http://testserver2.com/photos/5186145181.jpg" alt="" style="border: medium none" /></div><br />test messages and so on <br /><br />" I want to grab image url "http://testserver2.com/photos/5186145181.jpg", and put this into "img_link_results". $img_linkA = explode(' ', $img_link); $img_link_results = array();

How can I get preg_match_all to match angle brackets?

家住魔仙堡 提交于 2021-01-28 15:46:34
问题 I know it's probably a dumb question, but I am stuck trying to figure out how to make preg_match_all to do what I want... I want to match strings that look like <[someText]> Also, I would like to do this in a lazy fashion, so if a have a string like $myString = '<[someText]> blah blah blah <[someOtherText]> lala [doNotMatchThis] '; I would like to have 2 matches: '<[someText]>' and '<[someOtherText]>' as opposed to a single match '<[someText]> blah blah blah <[someOtherText]>' I am trying to

How can I get preg_match_all to match angle brackets?

可紊 提交于 2021-01-28 15:37:01
问题 I know it's probably a dumb question, but I am stuck trying to figure out how to make preg_match_all to do what I want... I want to match strings that look like <[someText]> Also, I would like to do this in a lazy fashion, so if a have a string like $myString = '<[someText]> blah blah blah <[someOtherText]> lala [doNotMatchThis] '; I would like to have 2 matches: '<[someText]>' and '<[someOtherText]>' as opposed to a single match '<[someText]> blah blah blah <[someOtherText]>' I am trying to

Extract year from a string using PHP regex

陌路散爱 提交于 2021-01-27 19:02:23
问题 I want to extract year from a string. I got an incomplete solution. My string will be always like: Please message mpg of jazz 2014 and 2015+ to my mobile number +123456789 I have tried the following regex; preg_match_all('!\d{4}+| \d{4}+\W!', $str, $matches); This will output the following array. Array ( [0] => Array ( [0] => 2015 [1] => 2014+ [2] => 1234 [3] => 5678 ) ) I need to get only the year portion with + symbol if any. I.e, i want only this: Array ( [0] => Array ( [0] => 2015 [1] =>

PHP split string on word before colon

[亡魂溺海] 提交于 2020-07-31 06:01:25
问题 I have a string that looks like this: aaaaa: lorem ipsum bb: dolor sit amet ccc: no pro movet What would be the best way to split the string into an array and get the following result in PHP? array[0]='aaaaa: lorem ipsum'; array[1]='bb: dolor sit amet'; array[2]='ccc: no pro movet'; I can write a function that finds the position of each ":", finds the length of the word before it, and splits the string. But I guess there is an easier way using regular expressions? 回答1: For this kind of job, I

Pattern to find specific text in PHP in given text [duplicate]

血红的双手。 提交于 2020-05-09 17:20:45
问题 This question already has answers here : How do I extract data from JSON with PHP? (7 answers) Extract JSON from HTML source and use it (1 answer) Extract JSON object from html using PHP regex (1 answer) Closed last month . I have trouble to find specific object with preg_match_all pattern. I have a text. A lot datas. But I would like to find just one specific Like I have a string of text sadasdasd:{"website":["https://bitcoin.org/"]tatic/cloud/img/coinmarketcap_grey_1.svg?_=60ffd80');display

Regex for text between double square brackets

老子叫甜甜 提交于 2020-02-08 04:53:11
问题 this is my sample text: text text text [[{"fid":"3228","view_mode":"full","fields":{"format":"full","field_file_image_alt_text[und][0][value]":"text text text","field_file_image_title_text[und][0][value]":"","field_file_image_gallery_content[und][0][value]":"","field_file_image_gallery_content[und][0][format]":"full_html"},"type":"media","link_text":null,"attributes":{"alt":"text text","height":"647","width":"421","class":"media-element file-full"}}]] I want to extract the text between the