我必须分开课程名称,教师姓名和课堂。
Progr.al.JanekManderÕ405 Arv.võr.TomKülaotsÕ205
Progr.al。是课程名称,Janek Mander是教师姓名,Õ405是课堂。 Arv.võr。是课程名称,TomKÜlaots是教师姓名,Õ205是课堂。
我必须将它们分开,以便我可以识别它们......可能是数组
info[0] = "Progr.al."
info[1] = "Janek Mander"
info[2] = "Õ 405"
现在我有了这个想法...如果我能检测到大写字母并用#{uppercaseletter}取代那个字符串那么我就可以将它爆炸......Õ405我可以爆炸,因为每个教室都有一个Õ之前它们。
WellProgrl.al.JanekManderÕ405......只有三个大写字母......老师的名字总是第二个大写字母......有什么办法我可以用它来做我的推荐或者我必须重写dom脚本吗?
到目前为止整个代码......
<!doctype html>
<html>
<head>
<title>Ilus tunniplaan</title>
<style>
.tund
{
width: 140px;
width: 405px;
border: 1px solid black;
}
.
</style>
</head>
<body>
<?php
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'Off');
ini_set('log_errors', 'Off');
function grab_page( $site )
{
$ch = curl_init( );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
curl_setopt( $ch, CURLOPT_TIMEOUT, 40 );
curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookie.txt" );
curl_setopt( $ch, CURLOPT_URL, $site );
ob_start( );
return curl_exec ( $ch );
ob_end_clean( );
curl_close ( $ch );
}
$html = grab_page( "http://web.ametikool.ee/tunniplaan/11.%20n%e4dal%2008.11%20-%2013.11/" );
$dom = new domDocument;
/*** load the html into the object ***/
$dom->loadHTML($html);
/*** the table by its tag name ***/
$tables = $dom->getElementsByTagName('table');
/*** get all rows from the table ***/
$rows = $tables->item(0)->getElementsByTagName('tr');
/*** loop over the table rows ***/
foreach ($rows as $row)
{
$id = $id + 1;
if( $id > 16 )
{
/*** get each column by tag name ***/
$cols = $row->getElementsByTagName('td');
/*** echo the values ***/
for ( $counter = 0; $counter <= 9; $counter += 1)
{
$phrase = $cols->item($counter)->nodeValue;
echo $phrase . "<br/>\n";
}
}
}
?>
</body>
</html>
答案 0 :(得分:1)
整蛊,但我会这样做:( for
循环内部)
for ( $counter = 0; $counter <= 9; $counter += 1)
{
$phrase = $cols->item($counter);
$breaklines = $phrase->getElementsByTagName('br');
if($breaklines->length == 2)
{
$br = array();
for($i=0;$i<2;$i++)
{
$br[$i] = $breaklines->item($i);
}
//Don't try to put this two for-loops into one.
for($i=0;$i<2;$i++)
{
$phrase->replaceChild($dom->createTextNode('|'), $br[$i]);
}
print_r(explode('|',$phrase->nodeValue)) . PHP_EOL;
}
}
答案 1 :(得分:0)
我认为如果您对输入数据有一些清晰的模式,那么您可以使用正则表达式来获得更好的解决方案。