过期域名预定抢注

 找回密碼
 免费注册

求大神。。。

[複製鏈接]
發表於 2014-10-21 21:56:41 | 顯示全部樓層 |閱讀模式
懸賞20點點已解決
本帖最後由 xx19941215 於 2014-10-21 22:02 編輯
4 B; [. h) R- O$ Y& {2 y
9 v' Q, H/ ^6 C1 I8 O' v4 W代碼[mw_shl_code=php,true]<?php
2 E5 H, O4 j0 Xfunction get_td_array($table) {7 [( l; V, z6 p7 ~7 q0 d" m
        $table = preg_replace("'<table[^>]*?>'si","",$table);0 _. i! \8 P. L. ]( M; y
        $table = preg_replace("'<tr[^>]*?>'si","",$table);$ d8 h' S* h! @8 g# M
        $table = preg_replace("'<td[^>]*?>'si","",$table);6 Y4 @; u( V" S
        $table = str_replace("</tr>","{tr}",$table);9 p8 V5 o' V2 @, T9 W
        $table = str_replace("</td>","{td}",$table);+ R. F: L4 O6 U0 P$ z4 Q, y
        //去掉 HTML 標記
7 R. w9 h4 C, @$ C, E; i        $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);$ n. |  U7 v0 ^0 w& L
        //去掉空白字符
& @# M" N, r8 b( E& e        $table = preg_replace("'([rn])+'","",$table);
0 C; B" z9 q( h7 M/ h8 a        $table = preg_replace('/ /',"",$table);" R3 H& A  B* Y+ y9 u- x' ?
        $table = str_replace(" ","",$table);; d: L3 T) F- b$ D: @: k8 V$ V& H9 e
        $table = str_replace(" ","",$table);. G% [0 }( ]& k  E
        $table = explode('{tr}', $table);
8 S3 E+ ~& n6 A+ o, w        array_pop($table);& m% Q, q) w4 ]# ?" c2 `) J# z
        foreach ($table as $key=>$tr) {6 q7 ~$ C& X4 m* d6 T* \
                $td = explode('{td}', $tr);
3 g& n4 e2 q5 v                array_pop($td);
6 D7 ~$ [1 \) c4 H% O' D  g4 f                $td_array[] = $td;
, `1 P: x4 r, {# R# W  P7 ?5 j. G        }/ o5 {$ n* A' |4 [0 p
        return $td_array;8 s8 s0 U4 z8 }# C  Q5 |* [
}
9 i6 y7 Y8 @( X5 W  //下載HTML網頁0 U- R# _. X6 v" U: j1 S6 j
  $s=file_get_contents('http://chengji.lideping.com:7000/exam/query/query.jsp?logname=20133011235');
( Q- k, U5 X2 M$ [* H  $s=mb_convert_encoding("$s", "UTF-8", "GBK");  //編碼轉換
( a- }2 z+ @1 l  //獲取最後一個table內容) L% U$ M3 K5 t2 F- B
  $s=substr($s,strrpos($s,'<table'));& \- T! v* N, Z! V% f* ]9 p# M
  $s=substr($s,0,strpos($s,'</table>')+8);
, S# ~% E! q1 d# Q" l4 Y, Y  //刪除超鏈接
( P( z) ?. M" A( [  $s=preg_replace('|<a href.*?</a>|','',$s);
+ J6 V3 t6 s. S6 I, M1 g! o, m$s=preg_replace('|<td align=\'center\'></td>|','',$s);//刪除多餘空格; y9 A# r2 O! p% H6 f1 G

  ~1 t; ?5 f! c+ A8 e  echo $s;; a7 U8 P" `0 C8 b5 p* r
  preg_match_all('/<table [^>]*>([\s\S]*?)<\/table>/',$s,$table);//用正則表達式將課表的表格取出9 H4 \' d7 _) C4 K
  $arr = get_td_array($table[0][0]);//執行函數/ n8 C0 J; G5 M/ n7 x
  print_r($arr);' i9 G: T8 M( s9 l! v0 t, u6 g
?>
# ]3 \+ ^: ^( ]2 k* b[/mw_shl_code] 函數是將表格轉換為數組的函數,網上找的。。問題是: 2014-10-21_220010.jpg

; F: B9 b9 R  [" A* ]' P# m6 ~4 L. L  ^* e/ C4 r

最佳答案

查看完整內容

樓主結賬! 人呢

點評

不好意思,这里大神多,就来这里问了,小弟php,正则,基本啥都不会,着这些代码还费了2个小时  發表於 2014-10-21 22:03
回復

使用道具 舉報

發表於 2014-10-21 21:56:42 | 顯示全部樓層
樓主結賬!                      人呢
7 u8 x8 p" X, `3 W4 h: ]6 ^
回復

使用道具 舉報

 樓主| 發表於 2014-10-21 22:14:25 | 顯示全部樓層
[mw_shl_code=php,true]<?php( ?' }  ]( D3 f5 y( K: {
header('Content-Type:text/html;charset:Utf-8');4 S7 l7 m& f" R! w
function get_td_array($table) {, N2 E, ?+ O* s
        $table = preg_replace("'<table[^>]*?>'si","",$table);
, s+ U; t& L9 K* w& v        $table = preg_replace("'<tr[^>]*?>'si","",$table);
3 h! O* E% X# ~; U" y4 d  N4 A        $table = preg_replace("'<td[^>]*?>'si","",$table);3 P' r5 @, S/ v; P. E$ T
        $table = str_replace("</tr>","{tr}",$table);
  n4 ?: d" a# y1 o5 [        $table = str_replace("</td>","{td}",$table);" M. h, }5 R3 G2 l. }
        //去掉 HTML 標記8 j9 z2 D3 }+ Z4 V( X
        $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);
6 J8 r; t9 a: r0 p4 I        //去掉空白字符- I- s$ |0 d6 G+ O6 x* `- ~7 Z
        $table = preg_replace("'([rn])+'","",$table);
$ ^, _$ _1 w$ |* T" v, o$ e/ ~+ U/ w        $table = preg_replace('/ /',"",$table);9 [6 H& `/ y" F$ S0 g
        $table = str_replace(" ","",$table);: I/ x, `+ F1 w, T( C* X+ g
        $table = str_replace(" ","",$table);/ n5 L% l4 R6 a' B
        $table = explode('{tr}', $table);
8 u! i' y! K: F6 ~" M1 ^; [        array_pop($table);7 n- p! Q7 {1 ~0 d
        foreach ($table as $key=>$tr) {4 N0 H7 L6 Z* `. Q( W
                $td = explode('{td}', $tr);
! s8 ?1 e0 r5 M5 y+ Z                array_pop($td);
4 C$ ]4 w$ |6 H2 z! ]* c                $td_array[] = $td;
0 ]% f! S! j3 n) ~        }+ D( v; G+ F9 r4 n. q
        return $td_array;8 d* o# E! z) K- y- c6 s8 P; h- c4 m
}
, B  n5 |# ]2 P) F* E  //下載HTML網頁
" L4 u1 B4 I, z  $s=file_get_contents('http://222.88.107.92/exam/query/query_detail.jsp?examid=2014102014&paperid=100094');) |- M$ m! k# I
  $s=mb_convert_encoding("$s", "UTF-8", "GBK");  //編碼轉換
  c7 o6 T% I8 |% k2 B: n" a  //獲取最後一個table內容
; j* G7 M! C' ?( i" p/ `* G6 y  $s=substr($s,strrpos($s,'<table'));
6 O- @9 R$ j4 o& E/ u8 E  $s=substr($s,0,strpos($s,'</table>')+8);% S9 L* F: c, K1 @
  //刪除超鏈接
- L( l8 }. V" N5 a) h" s  $s=preg_replace('|<a href.*?</a>|','',$s);0 D% p2 [1 l# |8 P
  $s=preg_replace('|<td align="center" width="120">圖片</td>|','',$s);7 D. q* h5 o" M. Y
  $s=preg_replace('|<td align=\'center\'></td>|','',$s);
3 M6 p5 |  O& d7 F% D4 B( r  $s=preg_replace('|<td align="center" width="120">評閱老師</td>|','',$s);1 G! i$ ?6 s1 @4 H! a7 c) ^* _
  $s=preg_replace('|<td align=\'center\'>110(.*?)<br></td>|','',$s);" U* P- n3 \, g* Y6 ?* Q
  echo $s;9 ^& n, r8 Y3 w7 c
  preg_match_all('/<table [^>]*>([\s\S]*?)<\/table>/',$s,$table);//用正則表達式將課表的表格取出  g" t: p. S( h# V
  $arr = get_td_array($table[0][0]);//執行函數
* Q& Q: X0 m2 X; p  print_r($arr);: H9 x. T0 V! T; g
?>
" H8 ~* e7 G6 Y[/mw_shl_code] 2014-10-21_221318.jpg 6 T% d1 |- M% F1 i4 ?
回復

使用道具 舉報

 樓主| 發表於 2014-10-21 22:15:00 | 顯示全部樓層
一樣的代碼,上面的這個就輸出了完全的數組& t) }, |: M& b+ T/ d( r
回復

使用道具 舉報

發表於 2014-10-22 13:52:01 | 顯示全部樓層
[mw_shl_code=php,true]<!DOCTYPE html>
+ H( q9 f  D3 u* T<html lang="zh-cn">  W, J& o7 e- T3 h# X; g7 P) m
<head>
& e$ [. X4 O# @, p! \8 e) @<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ H3 O3 w$ w7 f- t0 Y" R  u' @<title>測試</title>% R5 F8 `( d- [4 c" ]
</head>* p# M: r+ ~3 Z2 p' k
<body>/ ?! c* @; t' b! M2 `- y/ b5 Y
<?php2 d, o; r7 i" U
function get_td_array($table) {
" b# W. [0 @5 l. T; J) O        //去掉table標籤上的屬性
& T1 z+ e" z, @, Q        $table = preg_replace("'<table[^>]*?>'si","",$table);
4 @, o0 d4 h  `; t5 N. o  E1 q        //去掉TR上的屬性% J, Y( W, Q: U1 V' j) \; x
        $table = preg_replace("'<tr[^>]*?>'si","",$table);$ W" z4 z; b8 [/ N5 c  X6 \
        //去掉td上的屬性9 m1 C7 G0 T+ ]# C
        $table = preg_replace("'<td[^>]*?>'si","",$table);0 z; R0 w- F3 y8 S" r8 w
        //標籤替換
, d( F8 O+ G$ ^# Y% l3 `        $table = str_replace("</tr>","{tr}",$table);
; T, R" Z2 i8 A8 J        $table = str_replace("</td>","{td}",$table);! ~0 E1 H  _) {6 p) C! P( [9 S

. ~6 O' }# ^3 Q) _/ b+ p  V) u        //去掉 HTML 標記
! D' x: |7 s) ^, O9 t6 T        $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);$ \' c# @0 M3 j# \% X
        //去掉空白字符/ p# y2 R! e  |: [) q1 w6 m2 @$ _
        $table = preg_replace("'([rn])+'","",$table);. L8 j7 w& j+ W; n. ~
        $table = preg_replace('/ /',"",$table);* |; `  B: ]5 l( s8 s; ^- m2 D
        $table = str_replace(" ","",$table);4 n. @. w' K+ r6 k: L
        $table = str_replace(" ","",$table);
) B) S1 N; a' w# \        $table = explode('{tr}', $table);$ {* M: a5 x6 A+ W$ Q- R- u, ]
8 L* K7 f& w& ]0 O4 f5 K! n: I
        //這裡打印出來是長度為2的數組。9 g" o/ h) M1 }2 W: F1 R
        print_r($table);4 V5 ^4 N  m& y/ Q6 ]
        //這句代碼有問題,這個會把數組的第二個元素刪掉,所以得不到想要的結果0 _0 }! a: N- ^% Z3 @( `
        //array_pop($table);4 N' w/ [- N: t
        9 p' v/ }9 S7 E, a8 v
        $td_array = array();9 Z4 ]) ?4 ^1 r7 r) F+ s- D; @

& M& l: ?' J( n) b( }0 U& r) J        foreach ($table as $key=>$tr) {. f% a+ V$ {# T
                $td = explode('{td}', $tr);
3 M. Z; o" L2 }- V* g                array_pop($td);
1 q! S2 V  o- E2 z! @  W( x% X                $td_array[] = $td;: b% {2 _: b" T* E. B' r& d' k
        }; _/ x% \! i/ ?8 f
        return $td_array;9 o  j: m3 \# W7 J5 Q! M# S
}/ v- M' o1 \  E4 Q. o" [
//下載HTML網頁" \; d0 O9 z! A3 W
$s=file_get_contents('http://chengji.lideping.com:7000/exam/query/query.jsp?logname=20133011235');- `1 h8 ^8 K- Q' s7 o3 m* a
$s=mb_convert_encoding("$s", "UTF-8", "GBK");  //編碼轉換
: v3 l2 j2 Y* A# g* U# |) B. v//獲取最後一個table內容* r( \4 d& i) J+ Q, u8 t, N* q4 o
$s=substr($s,strrpos($s,'<table'));
4 v. y9 h: J7 D! n5 E4 X# s" h$s=substr($s,0,strpos($s,'</table>')+8);
4 d/ A3 Z* T% Y* x7 u//刪除超鏈接, _& r- V: o) i5 H. q# d
$s=preg_replace('|<a href.*?</a>|','',$s);% R8 s" P" J! ]  {+ r  h
$s=preg_replace('|<td align=\'center\'></td>|','',$s);//刪除多餘空格% s) d; H* t" X! F

+ E0 [6 u- V: H5 n7 zecho $s;
; V' v+ L$ H9 Z0 Q! `  O1 a: }preg_match_all('/<table [^>]*>([\s\S]*?)<\/table>/',$s,$table);//用正則表達式將課表的表格取出
5 j9 G3 ]/ n0 t, g* ]' t+ h- @" C6 k( J: l9 @
$arr = get_td_array($table[0][0]);//執行函數# @2 U+ g  Y7 {2 c& r, ~
print_r($arr);
2 w8 f0 R/ |7 |% g6 U) M) ^, V  }& m?>
, s- ^  }2 f& }</body>5 {/ b3 l* D$ [; k8 x- v
</html>
# J8 a2 `' \5 A0 ^' ~[/mw_shl_code]: e# k+ o$ w6 {/ `2 S8 x. {  m

2 ~- V8 b( t) }" Q! i2 M' ?$ M已調整完全正確輸出,給樓主你註釋了哪句代碼的問題
. q) ?* N* p# L; P

評分

參與人數 1點點 +13 收起 理由
月光飞燕 + 13 認眞參與

查看全部評分

回復

使用道具 舉報

發表於 2014-10-22 13:53:15 | 顯示全部樓層
記得給懸賞!  20分啊,口水流出來了" \' w) z& @; R

點評

好的,终于来人了啊,我测试看看  發表於 2014-10-22 14:00
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 免费注册

本版積分規則

过期高净值品牌域名预定抢注

點基跨境 數位編輯創業論壇

GMT+8, 2025-5-11 22:19

By DZ X3.5

小黑屋

快速回復 返回頂部 返回列表