preg-match-all

Why would this regex return an error?

我们两清 提交于 2019-12-12 02:39:21
问题 Why does the following evaluate to true ? if(preg_match_all('%<tr.*?>.*?<b>.*?</b>.*?</tr>%ims', $contents, $x)===FALSE) {...} $contents , is retrieved using file_get_contents() from this source. The regex was simplified to troublshoot the problem. The code I was actually using was: if(preg_match( '%Areas of Study: </P>.*?<TABLE BORDER="0">(.*?)<TBODY>.*?</TBODY>.*? </TABLE>%ims', $contents, $course_list) ) { if(preg_match_all('%<TR>.*?<TD.*?>.*?<B>(.*?)</B>.*?</TD>.*?<TD.*?>.*?</TD>.*?<TD.*?

Convert JSON string to array WITHOUT json_decode

孤街醉人 提交于 2019-12-12 01:49:46
问题 I am using PHP on shared server to access external site via API that is returning JSON containing 2 levels of data (Level 1: Performer & Level 2: Category array inside performer). I want to convert this to multidimensional associative array WITHOUT USING json_decode function (it uses too much memory for this usage!!!) Example of JSON data: [ { "performerId": 99999, "name": " Any performer name", "category": { "categoryId": 99, "name": "Some category name", "eventType": "Category Event" },

Regex multiline mode not working as expected for optional group [duplicate]

喜你入骨 提交于 2019-12-12 01:46:03
问题 This question already has answers here : Regex multiline mode with optional group skip valid data (3 answers) Closed 2 years ago . I have a next text source: PHPUnit 5.7.5 by Sebastian Bergmann and contributors. .....................E.....R................................. 61 / 1485 ( 1%) ..................... 1485 / 1485 (100%) Time: 1.51 minutes, Memory: 102.00MB ---error details skipped--- ERRORS! Tests: 1485, Assertions: 14821, Errors: 1, Failures: 1. I need to parse in real time

Remove everything else from an image link but keep src

孤街醉人 提交于 2019-12-12 00:07:48
问题 I am trying to remove some atrtibutes from images but it removes only the name of atribute and keep the rest.. i have an image as shown bellow: <img class="aligncenter size-full wp-image-sd174" src="http://www.blahblah.com/wp-content/uploads/2016/06/07d333r.jpg" alt="alt title" srcset="http://www.blahblah.com/wp-content/uploads/2016/06/07d333r.jpg 700w, http://www.blahblah.com/wp-content/uploads/2016/06/07d333r.jpg 241w, http://www.blahblah.com/wp-content/uploads/2016/06/07d333r.jpg 624w"

preg_match_all after hash tag before next hash tag in a string

北城以北 提交于 2019-12-11 23:29:35
问题 I want to find (if they exist) any hash tags and get the first co-occurrence of each tag plus the text after it but before the next tag if another exists. *Not all message strings carry a hash tag! Here is what I am trying to do: List of possible string examples sent to script: 1) $message = 'Added some new stuff'; 2) $message = ' #BALANCE balanced movement of X'; 3) $message = ' #CHANGE some log text #FIX some other log text'; $num = prereg_match_all('@?????@', $message, $matches); This is

Catching ids and its values from a string with preg_match

左心房为你撑大大i 提交于 2019-12-11 20:15:14
问题 I was wondering how can I create preg_match for catching: id=4 4 being any number and how can I search for the above example in a string? If this is could be correct /^id=[0-9]/ , the reason why I'm asking is because I'm not really good with preg_match . 回答1: for 4 being any number, we must set the range for it: /^id\=[0-9]+/ \ escape the equal-sign, plus after the number means 1 or even more. 回答2: You should go with the the following: /id=(\d+)/g Explanations: id= - Literal id= (\d+) -

preg_match to find a word that ends in a certain character

浪尽此生 提交于 2019-12-11 19:29:38
问题 I am trying to make a small program that searches within a timer (with this format 00d 00h 00m 00s) and returns the days into one variable, the hours into another, etc. This is some of my code: $time1 = "Left: 11d 21h 50m 06s <\/div>" preg_match_all("/ .*d/i", $time1, $timematch); // Day $time1day = $timematch[1]; // Saves to variable preg_match_all("/ .*h/i", $time1, $timematch); // Hour $time1hour = $timematch[1]; // Saves to variable preg_match_all("/ .*m/i", $time1, $timematch); // Minute

PHP regex match specific URL and strip others

穿精又带淫゛_ 提交于 2019-12-11 17:58:56
问题 I wrote this function to convert all specific URLs(mywebsite.com) to links, and strip other URLs to @@@spam@@@. function get_global_convert_all_urls($content) { $content = strtolower($content); $replace = "/(?:http|https)?(?:\:\/\/)?(?:www.)?(([A-Za-z0-9-]+\.)*[A-Za-z0-9-]+\.[A-Za-z]+)(?:\/.*)?/im"; preg_match_all($replace, $content, $search); $total = count($search[0]); for($i=0; $i < $total; $i++) { $url = $search[0][$i]; if(preg_match('/mywebsite.com/i', $url)) { $content = str_replace(

Warning: preg_match_all() [function.preg-match-all]: Unknown modifier 'g'

a 夏天 提交于 2019-12-11 16:35:27
问题 Errors: Warning: preg_match_all() [function.preg-match-all]: Unknown modifier 'g' in /Users/julian/Sites/abc.php on line 23 Warning: preg_match_all() [function.preg-match-all]: Unknown modifier 'g' in /Users/julian/Sites/abc.php on line 23 Here is my code: <?php class Crawler { protected $markup = ”; public function __construct($uri) { $this->markup = $this->getMarkup($uri); } public function getMarkup($uri) { return file_get_contents($uri); } public function get($type) { $method = "_get

PHP: preg_match_all() - how to find all occurrences of OR seperated substrings with a regex correctly?

白昼怎懂夜的黑 提交于 2019-12-11 15:44:03
问题 My task is to find all consecutive number in a string of only numbers. However I am not searching for a better regex to do this, but for a correct regex of matching substrings. This is how I build my regex: $regex = ""; for($i=0;$i<10;$i++) { $str = ""; for($a=0;$a<10;$a++) { if($a > $i) { $str .= $a; if(strlen($str)>1) { $regex .= "|".$str.""; } } } } $myregex = "/".ltrim($regex,"|")."/"; echo $myregex; Result: /12|123|1234|12345|123456|1234567|12345678|123456789|23|234|2345|23456|234567