Skip to content

Instantly share code, notes, and snippets.

@carschrotter
Created August 16, 2017 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carschrotter/905f98ea70246b5f8a6e4d3cfd255f2d to your computer and use it in GitHub Desktop.
Save carschrotter/905f98ea70246b5f8a6e4d3cfd255f2d to your computer and use it in GitHub Desktop.
<?php
/**
* Removed the house number from a german like address
* @param string $street
* @return string
*/
function removeHouseNumber($street) {
// removes the last occurrence of a house number type specification: 12. Februar-Platz 1A = 1A
//entfernt letztes vorkommen einer Hausummerntypischen Angabe: 12. Februar-Platz 1A = 1A
return \preg_replace('/([0-9\\-\\/ ]+?[a-z]?)$/i', '', $street);
}
//Example:
//find streetname
echo removeHouseNumber('12. Februar-Platz 1A'); // 12. Februar-Platz
//find housnumber
echo trim(str_replace(removeHouseNumber('12. Februar-Platz 1A'))) // 1A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment