代码拉取完成,页面将自动刷新
<?php
/**
* 获取慕课网某个课程的列表章节
*/
/**
* 获取列表
* @param $url
* @param $is_title
* @return array
* @throws Exception
*/
function GetList($url, $is_title)
{
if (empty($url)) {
throw new Exception('链接为空');
}
$content = file_get_contents($url);
$pattern = '/<i\sclass="imv2-play_circle\stype"><\/i\>\s+(.*)\n/';
preg_match_all($pattern, $content, $res);
$res = isset($res[1]) ? $res[1] : '';
if (empty($res)) {
throw new Exception('获取不到当前页面的列表');
}
$result = [];
// 对字符串进行去除首尾空白符以及加上markdown的标题
foreach ($res as $key => $value) {
if ($is_title) {
$result[] = '## ' . trim($value);
} else {
$result[] = trim($value);
}
}
return $result;
}
try {
$url = trim($_POST['url']);
$is_title = intval($_POST['is_title']);
$is_title = $is_title == 0 ? 0 : 1;
$result = GetList($url, $is_title);
$result = [
'data' => $result,
'status' => 1
];
echo json_encode($result);
exit();
} catch (Exception $e) {
echo json_encode(['data' => $e->getMessage(), 'status' => 0]);
exit();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。