Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@clone1018
Created May 2, 2014 14:59
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 clone1018/0a26a651da83dcffc6d9 to your computer and use it in GitHub Desktop.
Save clone1018/0a26a651da83dcffc6d9 to your computer and use it in GitHub Desktop.
<?php
function splitAddress($address, $width = 35) {
if (strlen($address) < $width)
return array('address1' => $address, 'address2' => null);
$string = wordwrap($address, $width);
$full = explode("\n", $string);
$address1 = $full[0];
$address2 = $full[1];
if (is_numeric(substr($address2, 0))) {
// We want to take the last word of $address1, remove it and prepend it to $address2
$pattern = '/[^ ]*$/';
preg_match($pattern, $address1, $results);
$address1 = trim(preg_replace($pattern, '', $address1));
$address2 = $results[0] . ' ' . $address2;
}
return array('address1' => $address1, 'address2' => $address2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment