[英]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.