Created
May 2, 2014 14:59
-
-
Save clone1018/0a26a651da83dcffc6d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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