正则表达式
PHP在使用正则匹配的时候需要使用“/”符号,称为定界符,“/”定界符之间的部分才是有效的匹配表达式
单引号&&双引号
在PHP中,双引号串中的内容可以被解释或替换,而单引号串中的内容总被认为是普通字符。所以,当我们想在字串中进行变量代换和包 含\n(换行符)等转义序列时,就应该使用双引号。
实现直播源普通格式转DPL格式
以下是第一个尝试例子,代码分别存储为*.html和todpl.php放在安装有PHP环境的服务器网站同一目录下,打开html文件输入示例内容,点击提交,获得结果。
<!DOCTYPE html> <html> <head> <meta lang="en"> <meta charset="UTF-8"> <title>格式转换</title> <style type="text/css"> .txtarea{ height:420px; width:600px; } </style> </head> <body> <form action="todpl.php" method="post"> <textarea class="txtarea" name="zbytxt"></textarea> </br> <input type="submit" value="提交"> </form> </body> </html>
以下是PHP文档的部分..
//todpl.php文件 <?php $contents = $_POST['zbytxt']; $acontents = explode("\n",$contents); $count = 0; define("DPLHEAD", "DAUMPLAYLIST playname= topindex=0 "); echo DPLHEAD; foreach($acontents as $itemtv) { $patterna= '/(.*?),([a-zA-Z0-9]{2,6}:[\S]*)/'; $statusmatch = preg_match($patterna,$itemtv,$matches);//print_r($matches); if($statusmatch == 1){ echo $count.'*file*'.$matches[2].' '; echo $count.'*title*'.$matches[1].' '; echo $count.'*played*0'.' '; $count ++; } else{ //echo '匹配非直播源的行<br />'; } } ?>
打开html文件在文本区域输入以下示例内容
徐州-1,http://stream1.huaihai.tv/xwzh/sd/live.m3u8 徐州-2,http://stream1.huaihai.tv/jjsh/sd/live.m3u8 徐州-3,http://stream1.huaihai.tv/wyys/sd/live.m3u8 徐州-4,http://stream1.huaihai.tv/ggpd/sd/live.m3u8
后续
2018-03-28 终于搞出个能用的东西:/tvlistconvert.html
2018-04-01 把输入和结果整合在同一个页面