如何用正则表达式在一个字符串中查找另一个字符串?

下面是一个具体的例子,有关正则表达式的具体使用方法请参照本站的使用说明

 1<html>
 2<head><title>正则表达式</title></head>
 3<body>
 4<a href="./">返回列表</a><br/>
 5<form action="&lt;?echo $PHP_SELF;?&gt;" method="post">   
 6在<input name="string" type="text" value="&lt;?echo $string;?&gt;"/>中查找<input name="query" type="text" value="&lt;?echo $query;?&gt;"/><br/>
 7<input "checked";?="" $where="" $where)="" )="" <?if(!isset(="" echo="" name="where" or="" type="radio" value=""/>&gt;第二个字符串可以在第一个字符串的任何位置<br/>
 8<input "checked";?="" $where="^" $where)="" )="" <?if(isset(="" and="" echo="" name="where" type="radio" value="^"/>&gt;第一个字符串以第二个字符串开始<br/>
 9<input "checked";?="" $where=" $" $where)="" )="" <?if(isset(="" and="" echo="" name="where" type="radio" value=" $"/>&gt;第一个字符串以第二个字符串结束<br/>
10<input "checked";?="" $case))="" <?if(isset(="" echo="" name="case" type="checkbox" value="case"/>&gt;区分大小写<br/>
11<input type="submit" value="查询"/>
12</form>
13<?   
14if(isset( $string) and isset( $query) and $string<>"" and $query&lt;&gt;""){   
15if(isset( $case)){   
16$func = "ereg";   
17}   
18else{   
19$func = "eregi";   
20}   
21switch( $where){   
22case "^":   
23$query = "^" . $query;   
24break;   
25case " $":   
26$query .= " $";   
27break;   
28}   
29eval("\ $found = $func(\" $query\",\" $string\");");   
30if( $found){   
31echo "找到!";   
32}   
33else{   
34echo "未找到!";   
35}   
36}   
37?&gt;   
38</body>
39</html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus