How to extract a substring from a string in PHP until it reaches a certain character?

前端 未结 5 2108
野趣味
野趣味 2020-12-11 18:37

I have part of a PHP application which assess a long string input by the user, and extracts a number which always begins 20 characters into the string the user supplies.

5条回答
  •  执念已碎
    2020-12-11 19:17

    find first occurrence of double quote after 20 chars, substract 19 - that gives you length of desired substring:

    $dq = strpos($string,'"',19); //19 is index of 20th char
    $desired_string = substr($string,19,$dq-19);
    

提交回复
热议问题