即时通讯存在这个问题...我想知道你有没有任何想法如何解决它?PHP由大写字母分解?
我必须分开课程名称,教师姓名和课堂。
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我可以通过Õ爆炸,因为每个教室都有一个Õ在他们面前。
那么Progrl.al.JanekManderÕ405 ......只有三个大写字母......老师的名字总是第二个大写字母......有没有什么办法可以用我的advatage或做我必须重写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>
个人而言,我会建议放在一起的数据的初审一个更有组织的形式,依靠正则表达式和(
for
环内) 'preg_split()'](http://www.php.net/manual/en/function.preg-split.php)(使用正则表达式的'explode()')很脆弱。 – 2010-11-09 23:15:00在dev-null-dweller给了我一个解决方案之前,我使用了这个: $ TestStr =“Tom Kulaots”; $ s = preg_replace('/([^ \ s])([A-Z])/','\ 1#\ 2',$ TestStr); $ info = explode(“#”,$ s); $ TestStr = $ info [1]; $ info = explode(“Õ”,$ TestStr); $ name = $ info [0]; – 2010-11-12 00:42:35