簡體   English   中英

如何從圖像URL中提取中間數字

[英]How to extract the middle digit from the image url

如何修剪前6個數字和最后一個字符串以及下面網址的擴展名並顯示1337,(1337是圖像的ID。)

1330001337_jenir.jpg
$id = substr(strstr($name, '_', true), 5);

我會嘗試正則表達式:

preg_match("/(?:\d){6}(\d+)/", "1330001337_jenir.jpg", $matches);

echo $matches[2];

使用substr + explode來獲取您的號碼。

試試這個代碼塊 -

$mystr = "1330001337_jenir.jpg";

echo substr($mystr,6,4);

只是

<?php
 $myStr='1330001337_jenir.jpg';

 $strArray=explode($myStr,'-');
 $numStr=substr($strArray[0],6); //returns 1337

 $nameStr=substr($strArray[1],0,-4);  //returns jenir

 ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM