php在字符串中查找另一個(gè)字符串
更新時(shí)間:2008年11月19日 00:03:03 作者:
在php下實(shí)現(xiàn)從指定的字符串中搜索字符串
<a href="./">返回列表</a><br>
<form action="<?echo $PHP_SELF;?>" method="post">
在<input type="text" name="string" value="<?echo $string;?>">中查找<input type="text" name="query" value="<?echo $query;?>"><br>
<input type="radio" name="where" value="" <?if(!isset($where) or $where=="") echo "checked";?>>第二個(gè)字符串可以在第一個(gè)字符串的任何位置<br>
<input type="radio" name="where" value="^" <?if(isset($where) and $where=="^") echo "checked";?>>第一個(gè)字符串以第二個(gè)字符串開(kāi)始<br>
<input type="radio" name="where" value="$" <?if(isset($where) and $where=="$") echo "checked";?>>第一個(gè)字符串以第二個(gè)字符串結(jié)束<br>
<input type="checkbox" name="case" value="case" <?if(isset($case)) echo "checked";?>>區(qū)分大小寫(xiě)<br>
<input type="submit" value="查詢(xún)">
</form>
<?
if(isset($string) and isset($query) and $string<>"" and $query<>""){
if(isset($case)){
$func = "ereg";
}
else{
$func = "eregi";
}
switch($where){
case "^":
$query = "^" . $query;
break;
case "$":
$query .= "$";
break;
}
eval("$found = $func("$query","$string");");
if($found){
echo "找到!";
}
else{
echo "未找到!";
}
}
?>
</body>
<form action="<?echo $PHP_SELF;?>" method="post">
在<input type="text" name="string" value="<?echo $string;?>">中查找<input type="text" name="query" value="<?echo $query;?>"><br>
<input type="radio" name="where" value="" <?if(!isset($where) or $where=="") echo "checked";?>>第二個(gè)字符串可以在第一個(gè)字符串的任何位置<br>
<input type="radio" name="where" value="^" <?if(isset($where) and $where=="^") echo "checked";?>>第一個(gè)字符串以第二個(gè)字符串開(kāi)始<br>
<input type="radio" name="where" value="$" <?if(isset($where) and $where=="$") echo "checked";?>>第一個(gè)字符串以第二個(gè)字符串結(jié)束<br>
<input type="checkbox" name="case" value="case" <?if(isset($case)) echo "checked";?>>區(qū)分大小寫(xiě)<br>
<input type="submit" value="查詢(xún)">
</form>
<?
if(isset($string) and isset($query) and $string<>"" and $query<>""){
if(isset($case)){
$func = "ereg";
}
else{
$func = "eregi";
}
switch($where){
case "^":
$query = "^" . $query;
break;
case "$":
$query .= "$";
break;
}
eval("$found = $func("$query","$string");");
if($found){
echo "找到!";
}
else{
echo "未找到!";
}
}
?>
</body>
相關(guān)文章
PHP實(shí)現(xiàn)QQ空間自動(dòng)回復(fù)說(shuō)說(shuō)的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)QQ空間自動(dòng)回復(fù)說(shuō)說(shuō)的方法,涉及php基于curl調(diào)用自動(dòng)回復(fù)接口的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12學(xué)習(xí)php設(shè)計(jì)模式 php實(shí)現(xiàn)橋梁模式(bridge)
這篇文章主要介紹了php設(shè)計(jì)模式中的橋梁模式,使用php實(shí)現(xiàn)橋梁模式,感興趣的小伙伴們可以參考一下2015-12-12php緩沖 output_buffering和ob_start使用介紹
這篇文章主要介紹了php緩沖 output_buffering和ob_start的相關(guān)資料,需要的朋友可以參考下2014-01-01JS+PHP實(shí)現(xiàn)用戶(hù)輸入數(shù)字后顯示最大的值及所在位置
這篇文章主要給大家介紹了JS+PHP實(shí)現(xiàn)用戶(hù)輸入數(shù)字后顯示最大的值及是第幾個(gè)的相關(guān)位置,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面來(lái)一起看看吧。2017-06-06PHP并發(fā)多進(jìn)程處理利器Gearman使用介紹
這篇文章主要介紹了PHP并發(fā)多進(jìn)程處理利器Gearman使用介紹,需要的朋友可以參考下2016-05-05php使用curl打開(kāi)https網(wǎng)站的方法
這篇文章主要介紹了php使用curl打開(kāi)https網(wǎng)站的方法,涉及php使用curl連接網(wǎng)站及獲取信息的相關(guān)技巧,需要的朋友可以參考下2015-06-06