Answer the question
In order to leave comments, you need to log in
How to remove part of a string as quickly as possible?
There is a line like:
$string = '40|https://site1.com/files/02bea218b601ef2cbc74e08dc8d78_1000_1000.png;77|https://site1.com/files/29037cbdc27707fe2d6b2cf4d3924_1000_1000.png;78|https://site1.com/files/923b6f214f8bffcf20fbbebe5365b_1000_1000.png;85|https://site1.com/files/f8b6dbe261e89877e23e6a6f00003_1000_1000.png';
$result = '40,77,78,85'
Answer the question
In order to leave comments, you need to log in
$string = '40|https://site1.com/files/02bea218b601ef2cbc74e08dc8d78_1000_1000.png;77|https://site1.com/files/29037cbdc27707fe2d6b2cf4d3924_1000_1000.png;78|https://site1.com/files/923b6f214f8bffcf20fbbebe5365b_1000_1000.png;85|https://site1.com/files/f8b6dbe261e89877e23e6a6f00003_1000_1000.png';
$result = substr(preg_replace('/\|.*?(?:;|$)/', ',', $string), 0, -1);
echo $result; // 40,77,78,85
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question