can anybody help me solve this :
i got
$filename= "index 198.php";
i use this and failed
preg_match(" [a-zA-Z0-9]", $filename, $output);
what kind of regex pattern i have to use so the $output array will be consist a number only value.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to extract just the number from the file name you can do:
It assumes that the file name has just one group of digits. In case if there are more than one group of digits like
index 123 abc 456.phponly the first group will be matched.Note:
The regex used is:
(\d+)\d: short cut for[0-9]. Asingle digit
\d+: one or more digits, basicallya number
(): to group and remember the match.It will be remembered in
$matchesarrray.
##: delimiters. preg_ family offunctions expect the 1st argument
which is the regex to be inside a
pair of delimiter. You could have
used
'/(\d+)/'too.