indexofphp
㈠ php中那一個函數可以相當於javascript中的string.indexOf()
沒有
php用mb_strstr()查找字元串
㈡ php有沒有像js里indexOf lastIndexOf 這樣的函數
indexOf對應php的可以用strpos(), lastIndexOf對應php的strripos()
㈢ php有類似indexof的方法么
indexOf在大多數語言中是在字元串查找另一字元串首次出現的位置。
PHP中也有類似的方法:
mixedstrpos(string$haystack,mixed$needle[,int$offset=0])
strpos — 查找字元串首次出現的位置
返回 needle 在 haystack 中首次出現的數字位置。
haystack:在該字元串中進行查找。
needle:如果 needle 不是一個字元串,那麼它將被轉換為整型並被視為字元的順序值。
offset:如果提供了此參數,搜索會從字元串該字元數的起始位置開始統計。
返回 needle 存在於 haystack 字元串起始的位置(獨立於 offset)。同時注意字元串位置是從0開始,而不是從1開始的。
如果沒找到 needle,將返回 FALSE。
注意:與大多數語言的indexOf不同的是,如果沒有找到返回的是false而不是-1.
㈣ php如何查找頁面中某div中是否存在某字元串
var divs = document.getElementsByTagName('div');// 取得所有div元素
for(var i = 0; i < divs.length; i++) {// 遍歷
if('A' == divs[i].className) {// 檢查class是否A
if(divs[i].innerHTML.indexOf('B') > -1) {// div中是否有B
// 若有,執行你自己的代碼
}
}
}
㈤ PHP正則提取字元串
有{} () [] <>可以
<?php
$str = '中文abcd123${1,2,3,4,5}.jpg[123123]444<44g>44.124(j)12g4';
$search ='/[{(\[<](.*?)[})\]>]/';
preg_match_all($search,$str,$r);
print_r($r[1]);
?>
㈥ php 如何處理屏蔽index of
在PHP中處理字元串類似 indexof 的函數或方法有兩個,它們是 strpos 函數和 stripos 函數,這兩個函數的用法類似。
strpos 函數處理字元串時如果包含該字元串,則返回該字元串出現的第一次出現的位置,如果沒有出現則返回 false。對字元串大小寫敏感。
stripos 函數處理字元串時如果包含該字元串,則返回該字元串出現的第一次出現的位置,如果沒有出現則返回 false。對字元串大小寫不敏感。 有不會的可以問我或者和我一起在後盾人線上收費直播培訓里學習,這里還提供全套課程資料和課堂視頻,可以無限次反復觀看。可好了。⁽˙³˙⁾◟(๑•́ ₃ •̀๑)◞⁽˙³˙⁾
㈦ 有一個欄位 php中 我想截取這個欄位中某個字元之前的文字 請問如何寫
可以結合substr函數及strrpos函數使用,即用以下表達式即可獲得新的a值:
$newa = substr($a,0,strrpos($a,'&')); //新的$a值
比如:substr("123456777778",0,strrpos("123456777778",'7'))結果應該是否123456
參考:http://..com/question/281745831.html
㈧ 織夢手機端首頁無限刷新,點擊內頁自動跳回首頁無限刷新
要麼就是模板的問題,要麼就是你安裝出現了問題。模版設置錯誤可能性比較大,給你一段織夢的跳轉代碼進行參考
首頁
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.cfg_mobileurl/}/index.php";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
列表頁
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
內容頁
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.cfg_mobileurl/}/view.php?aid={dede:field.id/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
㈨ php中,關於文本框搜索功能
PHP code
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {$a[]="Anna1";
$a[]="Anna2";
$a[]="Anna3";
$a[]="Anna4";
$a[]="Anna5";
$a[]="Anna6";
$a[]="Brittany1";
$a[]="Brittany2";
$a[]="Brittany3";
$a[]="Brittany4";
$a[]="Brittany5";
$a[]="Brittany6";
$a[]="Brittany7";
$a[]="Cinderella1";
$a[]="Cinderella2";
$a[]="Cinderella3";
$a[]="Cinderella4";
$a[]="Cinderella5";
$a[]="Cinderella6";
$a[]="Cinderella7";
$a[]="Diana1";
$a[]="Diana2";
$a[]="Diana3";
$a[]="Diana4";
$a[]="Diana5";
$a[]="Diana6";
$a[]="Diana7";
$a[]="Eva";
$a[]="Fiona";
$a[]="Gunda";
$a[]="Hege";
$a[]="Inga";
$a[]="Johanna";
$a[]="Kitty";
$a[]="Linda";
$a[]="Nina";
$a[]="Ophelia";
$a[]="Petunia";
$a[]="Amanda";
$a[]="Raquel";
$a[]="Cindy";
$a[]="Doris";
$a[]="Eve";
$a[]="Evita";
$a[]="Sunniva";
$a[]="Tove";
$a[]="Unni";
$a[]="Violet";
$a[]="Liza";
$a[]="Elizabeth";
$a[]="Ellen";
$a[]="Wenche";
$a[]="Vicky";
//get the q parameter from URL
$q = $_POST["q"];
$r = preg_grep("/^$q/i", $a);
exit(join('<br>', $r));
}
?>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0-beta1.js"></script>
<script>
function showHint(s) {
if($.trim(s) == '') return;
$('#txtHint').css('display', '');
$('#txtHint').load('', {q : s});
}
</script>
<div>
<form action="gethint.php" method="get" name="q">
<input type="text" id="q" name="q" onkeyup="showHint(this.value)" style="width:300px; height:32px;" />
<input type="submit" style="width:80px; height:34px;" value="Search"/>
<p id="txtHint" style="width:600px;diplay:none"></p>
</form>
</div>