简体   繁体   English

php在x个字符后获取字符串

[英]Php get string after x characters

I have an array which returns me paths like these: 我有一个数组,它返回如下路径:

C:\xampp\htdocs\app\storage\app/img/img24.png"  


C:\xampp\htdocs\app\storage\app/img/img3.png"

I need to extract the number from those parts, in this case 24 and 3 and save them into another array. 我需要从这些部分(在本例中为24和3)中提取数字并将其保存到另一个数组中。 So far I extracted the length like this: 到目前为止,我提取的长度是这样的:

$pathLen = strlen(storage_path('app/img/'));

That returned me 45, but I dont know how to continue 那让我回到了45岁,但我不知道如何继续

preg_match('~img/img(.*?).png~', $arrayinput, $output);

print_r($output[1]);

You can get substr from the last / , then use intval() to get the int. 您可以从最后一个/获得substr,然后使用intval()获得int。 Live demo . 现场演示

<?php
$string = "C:\xampp\htdocs\app\storage\app/img/img24.png";
echo intval(substr($string, strrpos($string, '/') +4));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM