當前位置:首頁 » 編程語言 » php字元串提取數字

php字元串提取數字

發布時間: 2022-12-24 20:20:51

A. php正則表達式字元串中提取數字,並截取其中的6位

<?php
$str='b37ba964bb7dfab1869e1cf8';
$preg="/d/is";
preg_match_all($preg,$str,$arr);
$temp=implode('',$arr[0]);
echo$temp;//匹配的數字
echo'<br/>'.substr($temp,1,4);//第2位開始取4個
echo'<br/>'.substr($temp,2,5);//第3位開始取5個
?>

B. php正則表達式提取數字,字元串中提取數字

<?php

$str="sssefss$2345.1234dddfffeds$456$00.23RR";

$pattern='/$(d+.?d+)/';

if(preg_match_all($pattern,$str,$match)){
echo'<pre>';
print_r($match);
}else{
echo'沒有找到!';
}

結果:
Array
(
[0]=>Array
(
[0]=>$2345.1234
[1]=>$456
[2]=>$00.23
)

[1]=>Array
(
[0]=>2345.1234
[1]=>456
[2]=>00.23
)

)

C. php 找個能在字元串中取得數字的函數

給你量身寫了個函數,應該能滿足你的需求

functionstrint($str){
if($str){
preg_match("/d+/is",$str,$v);
}
$StrInt=@$v[0];
if($StrInt){
return$StrInt;
}else{
return$str;
}
}

D. php從字元串中截取數字

可以用正則表達式,例如:

<?php
$str="我最愛看的《西遊記》101頁";
if(preg_match('/《(.*?)》/',$str,$reg))echo'書名:'.$reg[1];
if(preg_match('/》(d+)/',$str,$reg))echo'頁碼:'.$reg[1];
?>

E. php 字元串轉換成數字

整數 intval($string, 10); 第二個參數表示轉換為10進制整數
不一定是整數 floatval($string)

F. php中提取字元串內小括弧中的數字正則表達式是什麼

$str="一二三四五ABN420122(電話:123455)";x0dx0a$reg= '/.*\(.*:(.*)\)/'//冒號和$str保持一致x0dx0a$reg= '/.*\(.*(\d{6,})\)/'x0dx0a$reg= '/.*\(.*[^\d](\d+)\)/'x0dx0apreg_match_all($reg,$str,$want);x0dx0aprint_r($want[1]);x0dx0ax0dx0a3種正則 都可以

G. php怎麼把字元串中的數字取出來

解決這個問題的辦法,可以使用如下方法:

一、通過遍歷字元串,並對字元進行判斷。

二、使用正則表達式,取出數字。

熱點內容
停車系統資料庫 發布:2025-05-17 17:44:02 瀏覽:290
羅技g502高級腳本 發布:2025-05-17 17:30:45 瀏覽:217
python解析post請求 發布:2025-05-17 17:27:19 瀏覽:696
社保測算密碼是什麼 發布:2025-05-17 17:25:09 瀏覽:157
phpini修改路徑 發布:2025-05-17 17:19:06 瀏覽:280
mac搭建php開發環境 發布:2025-05-17 17:18:22 瀏覽:782
佟大為關悅上超級訪問 發布:2025-05-17 17:09:50 瀏覽:310
閃迪存儲卡高速 發布:2025-05-17 17:09:14 瀏覽:470
ios文件加密插件 發布:2025-05-17 17:05:48 瀏覽:797
androidbutton自定義 發布:2025-05-17 16:58:34 瀏覽:169