I have a $value such as 22214-HAV.jpg or 22214 HAV.jpg (notice no dash)开发者_高级运维
I want to run a quick function to pull only the number from filename.
A quick solution, which make use of PHPs type juggling
$number = (int) $filename;
preg_match('/^\d+/' ,'22214-HAV.jpg', $matches);
var_dump($matches[0]);
Observations:
- This will only match numbers starting exactly from the beginning. Any position can be allowed by removing ^.
- This will match any sequence of digits and not actual numbers. Numbers can be restricted by using ([1-9]\d*|0)in place of\d+.
- If no match is found $matches[0]will benulland not an empty string.
Further reading:
- http://www.php.net/manual/en/function.preg-match.php
- http://www.regular-expressions.info/reference.html
You can use explode for this
   //for '-'
            list($reqval)=explode('-', $value); 
    //for space
            list($reqval)=explode(' ', $value); 
        echo $reqval
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论