Olipol Olipol -4 years ago 53
PHP Question

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. 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

Answer Source

You can get substr from the last /, then use intval() to get the int. Live demo.

<?php
$string = "C:\xampp\htdocs\app\storage\app/img/img24.png";
echo intval(substr($string, strrpos($string, '/') +4));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download