PHP Regex to Find Any Number at the Beginning of String

后端 未结 2 1709
别那么骄傲
别那么骄傲 2021-01-13 04:32

I\'m using PHP, and am hoping to be able to create a regex that finds and returns the street number portion of an address.

Example:

1234- South Blvd. Washing

2条回答
  •  一向
    一向 (楼主)
    2021-01-13 05:00

    Try this:

    $str = "1234- South Blvd. Washington D.C., APT #306, ZIP4523";
    preg_match("~^(\d+)~", $str, $m);
    var_dump($m[1]);
    

    OUTPUT:

    string(4) "1234"
    

提交回复
热议问题