简体   繁体   English

如何使用 PHP 分隔街道名称和门牌号码?

[英]How do I seperate street names and house numbers with PHP?

In Germany we have street names and house numbers.在德国,我们有街道名称和门牌号码。 I work with a database where both is stored in a single column (for example "Arnoldstraße 12") and I want to seperate both into single variables.我使用一个数据库,其中两者都存储在一个列中(例如“Arnoldstraße 12”),我想将它们分成单个变量。

I have this code:我有这个代码:


$street= $row[2]; //This row is from an array with values of the database. The other rows are submitted perfectly.
preg_match('/([^\d]+)(\d+.*)/', $street, $matches);
$street_new = trim($matches[1]);
$house_number= trim($matches[2]);  

while ($row = $jobDB->fetchArray($result)) {
        $this->setReturnValue('strasse', $street_new);
        $this->setReturnValue('hausnummer', $house_number);
        return;
    }

After that, I use a JS-Code to get that (and more values) into a form on a website.之后,我使用 JS 代码将其(以及更多值)放入网站上的表单中。 The other values get there without problems, just the street name and the house number are missing.其他值没有问题,只是缺少街道名称和门牌号码。

Here's the JS-code:这是JS代码:


var auto_complete = function() { 
    var kontonr = jr_get_value('tb_kundennummer');
    jr_execute_dialog_function('autoComplete', {kontonummer: kontonr}, mySuccessCallback);    
}

var mySuccessCallback = function(returnObject) {
    jr_set_value('tb_kunde_strasse', returnObject.result.street_new); 
    jr_set_value('tb_kunde_hausnummer', returnObject.result.house_number);
}

What am I doing wrong?我究竟做错了什么?

Thank you in advance: :)先感谢您: :)

Ok I found a solution.好的,我找到了解决方案。 After adding the code into the while-loop it worked perfectly:将代码添加到while循环后,它运行良好:

      while ($row = $jobDB->fetchArray($result)) {            
          $street= $row[2];
          preg_match('/([^\d]+)(\d+.*)/', $street, $matches); 
          $street= trim($matches[1]);
          $house_number= trim($matches[2]);
            
          $this->setReturnValue('strasse', $street);
          $this->setReturnValue('hausnummer', $house_number);

        return;
    }

I'm not much of a developer, but maybe it was because the $row only works if called after the fetchArray.我不是一个开发人员,但可能是因为 $row 只有在 fetchArray 之后调用时才有效。 But I'm not sure.但我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过肥皂在马真托街价值中检索门牌号码? - How do I retrieve house number in magento street value via soap? 如何在PHP中将一串单词拆分为单独的字符串变量? - How do I split a string of words into seperate string variables in PHP? 如何在 PHP 中分隔 CSV 标题和列 - How do I seperate CSV headers and columns in PHP 使用php regex获取街道名称和地区的ID - get id of street names and regions with php regex 如何通过AJAX将数据从AJAX PHP结果传递到单独的PHP函数? - How do I pass data from an AJAX PHP result to a seperate PHP function through AJAX? 如何在php中将19a史密斯街改为19A史密斯街 - How can I change 19a smith STREET to 19A Smith Street in php 如何在 PHP 中添加换行符以将我的表格 output 彼此分开 - How do i add a line break in PHP to seperate my form output from each other 如何使用PHP在单独的页面上回显wordpress特色图片? - HOw do I use PHP to echo wordpress featured images on a seperate page? 如何使用jQuery .append和window.location将内容从单独的.php / html文件加载到div中? - How do i load content from a seperate .php/html file into a div with jQuery .append and window.location? 由于列没有直接连接,如何用名称替换 ID 号? (PHP/MySQL) - How do you replace id numbers with names since the columns aren't joined directly? (PHP/MySQL)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM