Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在不总是存在的两个字符串之间查找列中的特定字符串?_Php_Mysql_Contao - Fatal编程技术网

Php 在不总是存在的两个字符串之间查找列中的特定字符串?

Php 在不总是存在的两个字符串之间查找列中的特定字符串?,php,mysql,contao,Php,Mysql,Contao,长话短说,假设我在“table”中一个名为“WhyIshisList”的列中有一个字段,其中包含: {example1:"hereistext";example2:"ohlookmoretext";example3:"isthisevenreal"} 考虑到example2并不总是存在,因为它也可能看起来像这样,我如何提取example1和example2之间的文本: {example1:"hereistext";example7:"ohlookmoretext"} SELECT `whyi

长话短说,假设我在“table”中一个名为“WhyIshisList”的列中有一个字段,其中包含:

{example1:"hereistext";example2:"ohlookmoretext";example3:"isthisevenreal"}
考虑到example2并不总是存在,因为它也可能看起来像这样,我如何提取example1和example2之间的文本:

{example1:"hereistext";example7:"ohlookmoretext"}
SELECT `whyisthisalist` REGEXP '\:([^;]*)'
FROM `table`
如果一切顺利,它应该返回“hereistext”

到目前为止,我的想法是:

$sql = "SELECT SUBSTRING(LEFT(whyisthisalist, LOCATE('\";', whyisthisalist) +0), LOCATE('example1:\"', whyisthisalist) +0, 100)
FROM table
WHERE LOCATE('\";', whyisthisalist) > 0
AND LOCATE('example1:\"', whyisthisalist) > 0 ORDER BY id DESC LIMIT 1";
需要做什么/不起作用:
我需要在上一个定位字符串之后获得下一个出现的“。这可能吗?或者还有其他解决方法吗?我很高兴能得到一些帮助。

以下正则表达式将为您提供从第一个冒号到第一个分号的所有内容:

\:([^;]*)
如下所示简化查询:

{example1:"hereistext";example7:"ohlookmoretext"}
SELECT `whyisthisalist` REGEXP '\:([^;]*)'
FROM `table`

您还可以对正则表达式使用:

(?<=example1:)(.+?)(?=\;)
(?