我的查询是:
$query = $mysqli->query("SELECT col3 FROM table WHERE col3!='' AND col1= 'bond'");
现在我需要从 col1 中获取所有内容,其中 col2 不是空白,然后 col3 值替换为所有 col1 值,例如<a href="#">col1</a>
col1 值是否存在于 col3 值中。
示例: Col3 值:
bond early 13c., "anything that binds," phonetic variant of band (1) (for vowel change, see long), influenced by O.E. bonda "householder," lit. "dweller" (see bondage). The verb is 1670s (trans.), 1836 (intr.). Legalistic sense first recorded 1590s.
假设在 col1 和 col2 上找到的 bind、bonda 或 sense 不为空,则将 bind、bonda 或 sense 替换为 b> 标签 Like <b>binds</b>, <b>bonda</b> or <b>sense</b>
。
替换后的结果如下:
bond early 13c., "anything that <b>binds</b>," phonetic variant of band (1) (for vowel change, see long), influenced by O.E. <b>bonda</b> "householder," lit. "dweller" (see bondage). The verb is 1670s (trans.), 1836 (intr.). Legalistic <b>sense</b> first recorded 1590s.
我试过:
$query = $mysqli->query("SELECT col3 FROM table WHERE col3!='' AND col1= 'bond'");
$query2 = $mysqli->query("SELECT col1 FROM table WHERE col2 !='' ORDER BY LENGTH(col1) DESC");
$row = $query->fetch_assoc();
$row2 = $query2->fetch_assoc();
$result = str_replace($row2['col1'], '<b>'.$row2['col1'].'</b>', $row['col3']);