Here is my regex:
$table_pattern = "/<TABLE.*?>(.*?)<\/TABLE>/is";
Like the title says, it works in 5.1 and 5.3, but not 5.2. I’m using it in this preg_match:
preg_match_all($table_pattern, $page_content, $table_content);
$table_content is NULL on 5.2, but populated on 5.1 and 5.3. Any idea as to why?
Additional details:
$car_count = 47; //How many cars are currently online
$page_content = file_get_contents('http://www.site.com/temps/inventory.cfm?ChangeItems='.$car_count);; // What page will be parsed
$page_start = 10277; //Where the parsing should start
$page_content = substr($page_content, $page_start); //Removes all of the text above the table we need
$table_pattern = "/\<TABLE.*?\>(.*?)\<\/TABLE\>/is";
preg_match_all($table_pattern, $page_content, $table_content); //Finds all tables inside of $page_content and fills the $table_content array
$final_content = $table_content[0][0]; //Setting the first table, which is the match we need, to $table
$final_content is coming up as NULL. Obviously there is more happening below this in my code but it’s irrelevant.
I solved my own problem by – wait for it – NOT using RegEx! But really, I initially thought this would be much faster than dealing with the PHP Simple HTML Parser, but it wasn’t. But I am still curious as to why this will not work in certain versions.
It is possible to parse XML in PHP with recursive regex, but please use an XML library instead of regex. It’s much cleaner and easier…
(Your code fails if you have nested “tables” in your XML…)
The PCRE is developed by another team than the php, and the older versions have bugs. Maybe there is a bug in the PCRE passed to the php 5.2 which is fixed by the later versions.
Another explanation could be, that you have unicode xml, and you didn’t use the “u” flag.
By me it works on php 5.2.17. Which version do you have?