我想使用 PHP 中的 substr 方法从文本文件中提取 2 条信息。一些示例行如下
CON8101 Residential Building/Estimating 6 hrs/w
CON8411 Construction Materials I 4 hrs/w
CON8430 Computers and You 4 hrs/w
我需要提取每门课程所需的小时数。我写的函数从行尾提取数字是否正确?我想出了这个功能:
function GetCourseHours($couseList)
{//using 7 character placements from the end, taking 1 value (number)
$courseHours = substr(courseList, -7, 1);
}
接下来,提取除 hrs/w 之外的所有内容,例如CON8101 Residential Building/Estimating。我不确定如何在 substr 中表达以从行中提取除最后 7 个字符空格之外的所有内容。仅获取课程名称和 ID。
function GetCourseName($courseList)
{//how do I only emit the last 7 placements of the txt string?
$courseName = substr(courseList, ..., ...)
}