MySQL查询内容到某个字符串和相同的字符串之后


MySQL query for content UP TO a certain string and AFTER same string

在查询结果中,我想存储导致 UP 到某个字符串的所有内容,</a> <a href="imgpath" imgsrc="imgpath"></a> 然后存储</a>到第二个变量之后的所有内容。

[编辑]问题的改写:

$row[post_content] 中的值类似于 "<ahref=''><image></a><p>copy</p>" ...

我需要将其拆分为$val1 = "<ahref=''><image></a>"; and $val2 = "<p>copy</p>";

这可能是用substr()完成的,但我不知道怎么做,我已经搜索过,但由于我在搜索中使用了术语"字符",因此在 mysql 中只发现了对错误字符集的引用。

这将做到这一点,假设val是你的列名:

select
    substr(val, 1, instr(val, '</a>') + length('</a>') - 1) as part1,
    substr(val, instr(val, '</a>') + length('</a>')) as part2;

这是一个测试:

set @val := 'one<a href="imgpath">two</a>three';
select
    substr(@val, 1, instr(@val, '</a>') + length('</a>') - 1) as part1,
    substr(@val, instr(@val, '</a>') + length('</a>')) as part2;
$tmp = explode('</a>', $yourStr);
print_r($tmp);

用mysql标记了你的问题,所以波西米亚人使用mysql给了你答案。请使用正确的标签和描述来获得正确的答案。