Tải bản đầy đủ (.pdf) (16 trang)

Regular Expressions

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (117.9 KB, 16 trang )


PHP/CURL Book with Examples


 
: !        &  

:   !        &  S
:   !        &  S:   !        &  S
:   !        &  S 



!       &   -  ! & -     & - "   & -   
 & !  0   -           & -   
  &   &  ! % & # - )   

/ !       & *!  !     ,       & !  -  # & ! 
     & 0   & &  !       &     -  -  &  -  0  
  #  # )      -  - &  &      B  & -     &   
 &  !  !  ?  %  &  BN 

!       &   &  % -        )     & ! !   
    &  ")   & -   %  -  &    &   "     &    & -  
& &  " & -    & !  


: 2   )     #  !   
: 2   )     #  !   : 2   )     #  !   
: 2   )     #  !   
     &  S


     &  S     &  S
     &  S 



"!        &   & #   -   & ) -  & & !  "&  ) +

.  & !   & ! &   
2%  -  & !   & ! 
3  & !     & ! 
4   & ! -      
5  / & - )  & -  

!       &      ) &        & " & ) 
 & !   !    *)   &   & )  - R       T,  
  )   & -  !  " & -  J% & )   -     &    
  % ) #       
: 3!        &  & 
: 3!        &  & : 3!        &  & 
: 3!        &  & 




 & ! !  *!       &  ,  )   ) & " & -   %  
 & &     - !   & - & !  & -   & ! J       !  
& - 


PHP/CURL Book with Examples



 



!        &  (  & &  & 

(  ) "  "4)      &     !       &  +





 ! +   !       &   &
! +   !       &   &! +   !       &   &
! +   !       &   & 


# !
!!
! * & !   & " & !  & ! K"  ) !  M,
.     & !    !       & ! % & &   & &    @
 &  %   ) 
=      & -    &  A -   #  & !     &  & -   & &  
 -  -  !  & !  "   #  - & &   
  ) !  X !  KM &  &   #  & !         
  &   QX !  K2M &  &   #  & !   & !   & - " & -  & 
X !  KM &  &   )    & !  - 


2
22
2

 ! +     
! +     ! +     
! +     @
@@
@&  &  % !       &   &
&  &  % !       &   &&  &  % !       &   &
&  &  % !       &   & 


# ! 
! ! 
! * & !   & " & !  & ! K"  ) !  M,
    & &  - &  ! *,    ! &    -  & &  & 
 & !    #    

3
33
3

  ! R  +    
 ! R  +     ! R  +    
 ! R  +    @
@@
@  # !       &   &
  # !       &   &  # !       &   &
  # !       &   & 



&  ! R  
 ! R   ! R  
 ! R  * & !   & " & !   # EK"  )   K"&   !  MM,
.     # E   !       & ! % & &   & 
=     % - - "&   -        X   KM 
&  &    -     & "X   KM  %   
 -      -   &  A -   #   & " & -  & 
 !   & #   & !   ! +

 ' R 1 ( ( .   R /   
=    !   " % )  & !     & -  &  & !      # 
 & - <    & !   & %   &  &   )  % ) & 
  &   ) &   & !   -  & !     & - J  & !   & 
  # E       !   %   #  & 43
 ! R  *, &  &  #     &      # 
 *&  ,#     ! R  *,     & !    
  ! R  R  *,
 ! R  R  *, ! R  R  *,
 ! R  R  *,& &  )  & &   &   & -  
  # E ! R  *, &  ( / .    &  - 

4
44
4

  ! R   +    
 ! R   +     ! R   +    
 ! R   +    @

@@
@  # !       & 
  # !       &   # !       & 
  # !       &  /  
/  /  
/  
  &
  &  &
  & 


 -  ! R   
 ! R    ! R   
 ! R   * -   & " -   & " -   # EK"& M,

PHP/CURL Book with Examples


 
.     # E     &  & -       & = 
    - "& & )    #   - Q  -  @"
&       - 
  &  ) &  &  &    NN& * & 44,X & " 
  # & !   - &  % )    &  #   - # ) 
    - # ) & J  &  A -   & &  & #  ; ; " & - NN
X     - # )    & 1  & & !   &    
 & -   ! *  & !  ,#  & &  #     & ! 
  #   & 
&  & !     &   &   #   &  -  ) 
 - # )  & &  # *+  & !   &  # -  )   

 -   & ,")   & &      NN&  &  )  #   & 
NN"    "  - &    ! R   *, & -  & &   
)    & NN#   &   - # )   "NN#   & 
 - # ) & & ! =&      &    NX [\     & 
  - X #   & " % & !     

5 
5 5 
5 

 ! R   + 
! R   + ! R   + 
! R   +   !       &  /    &
 !       &  /    &  !       &  /    &
 !       &  /    & 


 & ! ! R   
! R   ! R   
! R   * & !   & " & !   & " & !  & ! ,
    & &   &   & !      & "&     -  
   & 
 -  -  & !   & - * )  &  ! &   & !  
 & -   &   #   - ,
=   & &  &    &  A -   #  & !  "  &  ) &  &   #  & !  
  NN- ! "  #   - # )   & ! - ! J
  &  A -   #  & ! QNN  -  & & &    & !  & & 
  #  & !   ) #   -  &    ) # &  - "&    )  
 & - # )  & & !   &   
= &      & - &  & ! "&  & !  #  & -  &  & ! - 


6 
6 6 
6 

 ! R   +     # % Q  
! R   +     # % Q  ! R   +     # % Q  
! R   +     # % Q  @
@@
@&  &  % 
&  &  % &  &  % 
&  &  % 


 & ! ! R   * & !   & " & !   & " & !  & ! ,












PHP/CURL Book with Examples



 


: 4!        &       

 ! R    & &
 ! R    & & ! R    & &
 ! R    & & 


 %   -  &  &   ! R    & & 
* +  &  ! R  ,/  )   &   -  &  & " ! R   
  -    !       & =&    &   & !  - & "& )  
   & -  ) - #  ! %  ) 

<?php 
// Example reg001.php 
// Simple Regular Expressions in PHP 
// Copyright 
// Match some sub text inside a text string. 

// Example string 
$str = "Let's find the Name :<B>Muhammad Imran</B> <table> some table</table>and
some fonts tags of </html>"; 

// Let's perform the regex 
$flag = preg_match("/<B>(.*)<\/B>/", $str, $matches); 

// Check if regex was successful 
if ($flag = true) { 

// Matched something, show the matched string 
echo htmlentities($matches['0']); 

// Also how the text in between the tags 
echo '<br />' . $matches['1']; 
} else { 
// No Match 
echo "Couldn't find a match"; 
} 

?>



/  % & !  & - "J  #  # )  ! - -   =-  ?   &  ! 
-    ) "   # % -  &  &  &  
 ! R      !  &  )  !    &     #  # )  
  & 

  & -  !  &    # E & ! =     & -  &    & & ! 
( &  ) "-  !  &  & #  &  "#   )    & !  -  "
 & #  &  & ! "J  ! - -    


PHP/CURL Book with Examples


 
 ! R  R    & &
 ! R  R    & & ! R  R    & &

 ! R  R    & & 


  ! R    & &         & -    = )    &  & - 
/   &   & ! ")  & -    ! R  R    & & 
* +     &  ! R  R  ,

<?php
// Example reg002.php
// Simple Regular Expressions in PHP
// Copyright
// parsing name, email from hotmail contact html page.
// using php function preg_match_all
$str = '
<html>
<body>
<table border=0 cellpadding=0 cellspacing=0 width=100% class="EE"
id="ListTable">
<form name=doaddy action="/cgi-bin/doaddresses" method=POST>
<input type=hidden name="" value="">
<input type=hidden name=_HMaction value="">
<input type=hidden name=i>
<input type=hidden name=IsGroup>
<input type=hidden name=strUsrFltr value="">
<input type=hidden name=strUsrView value="">
<input type=hidden name=strAlphNav value="">
<input type=hidden name=a value=0aee4eac7ebe5d67fa50eb5267e959b02e
b61cb9ba63cb9598857c5a311822e5>
<tr height=26>
<td colspan=6 align=right style="BORDER-TOP:none;COLOR:#8D8D8D">

<font class="K">ALL</font>&nbsp;#&nbsp;A&nbsp;B&nbsp;<a href="java
script:AN("","","C")">C</a>&nbsp;D&nbsp;E&nbsp;F&nbsp;G&nbsp;H&nbsp;I&nbsp
;J&nbsp;<a href="javascript:AN("","","K")">K</a>&nbsp;L&nbsp;M&nbsp;N&nbsp
;O&nbsp;P&nbsp;Q&nbsp;R&nbsp;S&nbsp;T&nbsp;U&nbsp;V&nbsp;W&nbsp;X&nbsp;Y&n
bsp;Z&nbsp;&nbsp;</td>
</tr>
<tr id="messPrompt">
</tr>
<tr bgcolor=#DBEAF5>
<td width=1% height=24 align=center>&nbsp;<input name=allbox type=
checkbox onClick="CA()">&nbsp;</td>
<td width=1%>&nbsp;</td>
<td bgcolor=#A0C6E5>
<a href="javascript:AD("addrrev=1&addrsort=nick&strUsrFltr=&strUsr
View=&strAlphNav=")" title="Sort by Name" class="FF">
<img src=" hspace=3 borde
r=0 alt="sorted in ascending order">Name</a>
</td>
<td >
<a href="javascript:AD("addrrev=1&addrsort=email&strUsrFltr=&strUs
rView=&strAlphNav=")" title="Sort by E-Mail" class="FF">E-Mail</a>
</td>
<td>
<font class="FF">Phone</font>
</td>
</tr>
<tr name="" id="13bf6320-da8e-4d40-8759-3c4ab27e36a0">
<td align=center>

PHP/CURL Book with Examples



 
<input type=checkbox name="ADDR13bf6320-da8e-4d40-8759-
3c4ab27e36a0" onClick="CCA(this)" id="hotmail">
</td>
<td width=1%>
</td>
<td nowap>
<a href="#" onclick="javascript:DoAD("","&strUsrView=",event);retu
rn false;">cheema</a>
</td>
<td>
<a href="#" onclick="javascript:DC(event);return false;">cheema@gm
ail.com</a>
</td>
<td>
</td>
</tr>
<tr name="" id="2b151594-b7ed-4994-8953-44ace5bfc483">
<td align=center>
<input type=checkbox name="ADDR2b151594-b7ed-4994-8953-
44ace5bfc483" onClick="CCA(this)" id="hotmail">
</td>
<td width=1%>
</td>
<td nowap>
<a href="#" onclick="javascript:DoAD("","&strUsrView=",event);retu
rn false;">kahlid</a>
</td>

<td>
<a href="#" onclick="javascript:DC(event);return false;">khalid@ya
hoo.com</a>
</td>
<td>
</td>
</tr>
<tr name="" id="e7615392-aac4-45e2-87e8-96afa21eb928">
<td align=center>
<input type=checkbox name="ADDRe7615392-aac4-45e2-87e8-
96afa21eb928" onClick="CCA(this)" id="hotmail">
</td>
<td width=1%>
</td>
<td nowap>
<a href="#" onclick="javascript:DoAD("","&strUsrView=",event);retu
rn false;">khalid, imran</a>
</td>
<td>
<a href="#" onclick="javascript:DC(event);return false;">imran@hot
mail.com</a>
</td>
<td>
</td>
</tr>
<td colspan=5>&nbsp;</td>
</table>
</td>
<tr>
</table>

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×