You are not logged in.
Please let me know if a PHP syntax related question is not appropiate here. I am debugging an abandoned PHP 5.2.3 script from: http://outbreakmonkey.org/mythtv/csr0.3.php
This is the part of the code with the problem. I believe preg_match_all has an issue with PHP 5.6.
$cutlist=file("$recordingdir/$txtfile");
#Markssql will hold the lines of SQL to insert in to the DB.
$marks=array();
#Go through each line
foreach ($cutlist as $aline) {
#And match "One or more digit followed by one or more space/tab folowed by one or more digits again"
#ie. Look for two columns of numbers - get those numbers.
preg_match_all('/^([0-9]+)\s+([0-9]+)/',$aline,$result);
#if there numbers make sense, create some SQL to insert the record in to the database
if(!empty($result[1])) {
if (($result[1][0]>0)&&($result[2][0])>1) {
$marks[$result[1][0]]=MARK_COMM_START;
$marks[$result[2][0]]=MARK_COMM_END;
}
}
}
return($marks);
}
with a sample $cutlist being:
FILE PROCESSING COMPLETE 99042 FRAMES AT 2500
-------------------
27475 32467
52725 58360
86124 89494
96382 99042
The script works with PHP 5.6 but returns an output of 0 for these marks. PHP says the following in the change log:
Changelog
Version Description
5.4.0 The matches parameter became optional.
5.3.6 Returns FALSE if offset is higher than subject length.
5.2.2 Named subpatterns now accept the syntax (?<name>) and (?'name') as well as (?P<name>). Previous versions accepted only (?P<name>).
Does anyone good with PHP know how the syntax of preg_match_all could be changed to work with 5.6? Or maybe another function to do the same?
Thanks.
Last edited by wdirksen (2014-10-02 19:33:55)
Research | Trial | Make Mistakes | Ask questions | Learn | Repeat
Offline
The question should go to Programming & Scripting, I believe.
I doubt this has anything to do with `preg_match_all`. Looks more like the input file uses invalid line endings and `file` reads it as a single string instead of an array of lines. Then, obviously, the regex doesn't match the whole file.
I assume that what you have presented as `$cutlist` content is a single string element and not an array of strings.
Sometimes I seem a bit harsh — don’t get offended too easily!
Offline
Thanks mpan for your reply.
This is not a matter of strict debugging per se. This PHP script has worked for many in the past. Also the provided cutlist is a complete one and not a snippit. There is more online about preg_match_all and PHP regressions so I was hoping someone whould know an easy way out here. I don't think it has to do with foreach. I will try to track this down and learn from it, starting with trying an older PHP version with current ARCH and hoping it will not fyrk up other PHP stuff like mythweb.
Yeah. You're right about the Programming and Scripting. I didn't scroll down far enough I guess.
Research | Trial | Make Mistakes | Ask questions | Learn | Repeat
Offline
This turned out to be something simple.
The file command wasn't working because the pathway of the file wasn't specified in /etc/php/php.ini
Sweet, look Ma, no commercials
Research | Trial | Make Mistakes | Ask questions | Learn | Repeat
Offline