• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Extract house numbers from address string

phpregexstreet-address


PHP Snippet 1:

preg_match_all('!\s(\d.*)!', 'streetname 60/2/3', $matches);

PHP Snippet 2:

function getStreetNumberFromStreetAddress($streetAddress){
  $array = explode(' ',$streetAddress);

  if (count($array) > 0){
    foreach($array as $a){
      if (is_numeric($a[0])){
        return $a;
      }
    }
  }
  return null;
}

Related Snippets

Inserting Country Selection into MySQL PHP [duplicate]

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

Mysqli Output to a table

How to install PHP composer inside a docker container

Backend cannot be reached after Typo3 login screen

protect my blog content

unable to load your default controller on Codeigniter

Querying only one row from a one to many relationship laravel

Adding hreflang tags automatically in WordPress subdirectory multisite

ldap is missing from system when installing adldap2 in laravel

Not able to access model in the controller mautic

Why does codeigniter & Linux server throws unserialize() session data error when user tries to login

Can't find vendor/autoload.php for Ratchet

WooCommerce - unset "<product> removed notice…" on cart page

Updating and Synchronizing Woocommerce Subscriptions to Custom Date

About Contact Privacy policy Terms and conditions