Extract a single integer from a string

后端 未结 21 2477
一个人的身影
一个人的身影 2020-11-21 23:33

I want to extract the digits from a string that contains numbers and letters like:

"In My Cart : 11 items"

I want to extract the nu

21条回答
  •  感情败类
    2020-11-21 23:54

    try this,use preg_replace

    $string = "Hello! 123 test this? 456. done? 100%";
    $int = intval(preg_replace('/[^0-9]+/', '', $string), 10);
    echo $int;
    

    DEMO

提交回复
热议问题