gpt4 book ai didi

php - 在上一个定位命令之后定位特定字符串

转载 作者:行者123 更新时间:2023-11-29 21:31:23 25 4
gpt4 key购买 nike

所以我在这里得到了我的“小”代码:

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

//Verbindung
$connection = mysqli_connect('localhost', 'user', 'pw', 'db');

// search stuff
// Treuhandbetrag case 1
$suchstringanfang_treuhand1 = 'treuhand_betrag\"';
$suchstringende_treuhand1 = '\";';

// Treuhandbetrag case 2
$suchstringanfang_treuhand2 = 'treuhand_price\"';
$suchstringende_treuhand2 = '\";';

//queries
//Treuhandabfrage case 1
$query_treuhand1 = "SELECT SUBSTRING(LEFT(configuration, LOCATE('$suchstringende_treuhand1', configuration) +0), LOCATE('$suchstringanfang_treuhand1', configuration) +0, 100)
FROM tl_iso_product_collection_item
WHERE LOCATE('$suchstringende_treuhand1', configuration) > 0
AND LOCATE('$suchstringanfang_treuhand1', configuration) > 0 ORDER BY id DESC LIMIT 1";

//Treuhandabfrage case 2
$query_treuhand2 = "SELECT SUBSTRING(LEFT(configuration, LOCATE('$suchstringende_treuhand2', configuration) +0), LOCATE('$suchstringanfang_treuhand2', configuration) +0, 100)
FROM tl_iso_product_collection_item
WHERE LOCATE('$suchstringende_treuhand2', configuration) > 0
AND LOCATE('$suchstringanfang_treuhand2', configuration) > 0 ORDER BY id DESC LIMIT 1";

//results
// Treuhandbetrag
$result_treuhand1 = mysqli_query($connection, $query_treuhand1);
$result_treuhand2 = mysqli_query($connection, $query_treuhand2);

//Display results
if($result_treuhand2 === FALSE) {
echo mysqli_error($connection);
} else
while($row = mysqli_fetch_array($result_treuhand2)){
print_r($row[0]);
}

//Close connection
mysqli_close($connection);
?>

我基本上想做的是在之间找到一个字符串

treuhand_betrag

以及下一个发生

";

这是因为商店将所有属性数据存储在数据库的一个文本字段中。我知道这是一个紧急解决方案,但我迫切需要一些帮助。到目前为止,我的代码不会给我任何结果。如果我用一些独特的东西替换“;”,比如“treuhand_price”,它只在该字段中出现一次,我确实得到了想要的结果。

文本字段的外观:如果有人提供了所有信息,您可以期望该字段包含以下内容,例如:

a:14:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"37";s:15:"treuhand_betrag";s:4:"2000";s:13:"treuhand_price";s:2:"35";s:11:"abhol_firma";s:18:"NichtdieselbeFirma";s:13:"abhol_vorname";s:14:"AndererVorname";s:14:"abhol_nachname";s:15:"AndererNachname";s:12:"abhol_str_nr";s:15:"AndereStraße 7";s:9:"abhol_plz";s:6:"456465";s:9:"abhol_ort";s:12:"Dschingistan";s:10:"abhol_land";s:3:"Bla";s:13:"abhol_telefon";s:6:"564654";s:11:"abhol_email";s:10:"d.web@d.de";s:11:"bemerkungen";s:5:"aeawe";}

如果有人不太关心并且没有透露太多信息:

a:8:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"36";s:13:"treuhand_price";s:2:"35";s:13:"abhol_vorname";s:5:"Deniz";s:14:"abhol_nachname";s:5:"Cetin";s:12:"abhol_str_nr";s:10:"straße 38";s:9:"abhol_plz";s:5:"90461";s:9:"abhol_ort";s:9:"Nürnberg";}

如果能得到一些帮助或提示,我将非常高兴!提前致谢!

最佳答案

这就是你想要的吗?这有点棘手。因此,我反转字符串(和搜索字符串)以使用 SUBSTR_INDEX 从中获取其余部分。我已将您的字段名称更改为本示例中的 STRING

SELECT
SUBSTRING_INDEX(REVERSE(
SUBSTRING_INDEX(SUBSTRING_INDEX(
REVERSE('a:14:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"37";s:15:"treuhand_betrag";s:4:"2000";s:13:"treuhand_price";s:2:"35";s:11:"abhol_firma";s:18:"NichtdieselbeFirma";s:13:"abhol_vorname";s:14:"AndererVorname";s:14:"abhol_nachname";s:15:"AndererNachname";s:12:"abhol_str_nr";s:15:"AndereStraße 7";s:9:"abhol_plz";s:6:"456465";s:9:"abhol_ort";s:12:"Dschingistan";s:10:"abhol_land";s:3:"Bla";s:13:"abhol_telefon";s:6:"564654";s:11:"abhol_email";s:10:"d.web@d.de";s:11:"bemerkungen";s:5:"aeawe";}')
,'garteb_dnahuert'
,1),';"',-2)),'"',-1);

结果

2000

请告诉我您是否在搜索

我将我的答案复制到 mysql 客户端:

MariaDB [(none)]> SELECT
-> SUBSTRING_INDEX(REVERSE(
-> SUBSTRING_INDEX(SUBSTRING_INDEX(
-> REVERSE('a:14:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"37";s:15:"treuhand_betrag";s:4:"2000";s:13:"treuhand_price";s:2:"35";s:11:"abhol_firma";s:18:"NichtdieselbeFirma";s:13:"abhol_vorname";s:14:"AndererVorname";s:14:"abhol_nachname";s:15:"AndererNachname";s:12:"abhol_str_nr";s:15:"AndereStraße 7";s:9:"abhol_plz";s:6:"456465";s:9:"abhol_ort";s:12:"Dschingistan";s:10:"abhol_land";s:3:"Bla";s:13:"abhol_telefon";s:6:"564654";s:11:"abhol_email";s:10:"d.web@d.de";s:11:"bemerkungen";s:5:"aeawe";}')
-> ,'garteb_dnahuert'
-> ,1),';"',-2)),'"',-1);
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| SUBSTRING_INDEX(REVERSE(
SUBSTRING_INDEX(SUBSTRING_INDEX(
REVERSE('a:14:{s:6:"roller";s:1:"9";s:16:"treuhand_abfrage";s:2:"37";s:15:"treuhand_betrag";s:4:"2000";s:13:"treuhand_price";s:2:"35";s:11:"abhol_firma";s:18:"NichtdieselbeFirma";s:13:"abhol_v |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 2000 |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]>

关于php - 在上一个定位命令之后定位特定字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35223865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com