Files
2025-06-24 14:14:35 +02:00

65 lines
1.9 KiB
PHP

<?php
class InpostTools
{
/**
* @param $postcode
* @return string
*/
public static function setPolandPostCode($postcode)
{
if (strlen($postcode) == 5) {
$postcode = trim( substr_replace( $postcode, '-', 2, 0 ) );
}
return $postcode;
}
/**
* @param $phone
* @return string
*/
public static function setPhoneNumber($phone)
{
if (strlen($phone) > 9) {
$phone = trim(str_replace('-', '', $phone));
$phone = trim(str_replace(' ', '', $phone));
}
return $phone;
}
/**
* @param $streetStr
* @return array
*/
public static function split_street($streetStr)
{
// $re = '/(([0-9]\s)*)([\węąóśłżźćńŚŁŹŻ]*)\s(([0-9])([[:punct:])*([0-9a-zA-Z]*))/m';
$re = '/^([\w\s\W]+[\w\W]?)\s([\d\-\\\\\/\w]*)?/m';
preg_match_all($re, $streetStr, $matches, PREG_SET_ORDER, 0);
$match = isset($matches[0]) ? $matches[0] : array();
if (!empty($match)) {
$street = (!empty($match[1]) ? $match[1] : '') . (isset($match[3]) ? $match[3] : '');
} else {
$street = '';
}
$numberAll = isset($match[2]) ? $match[2] : '';
$nums = isset($match[4]) ? explode('/', $match[4]) : '';
$number = isset($nums[0]) ? $nums[0] : '';
$numberAddition = isset($nums[1]) ? $nums[0] : '';
return array('street' => $street, 'numberAll' => $numberAll, 'number' => $number, 'numberAddition' => $numberAddition);
}
public static function testRegexp()
{
$re = '/(([0-9]\s)*)([\w]*)\s(([0-9]\w)([[:punct:])*([0-9a-zA-Z]*))/m';
$str = 'grabowska 33a/11v';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
exit();
}
}