如何替换字符串中的多个单词,从中选择另一列为真的列?

时间:2016-10-11 10:19:07

标签: php mysql replace multiple-value

我的查询是:

$query = $mysqli->query("SELECT col3 FROM table WHERE col3!='' AND col1= 'bond'");

现在我需要从col1获取all,其中col2不为空,然后如果col3值中存在col1值,则将col3值替换为所有col1值,如<a href="#">col1</a>

示例: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上发现的结合,键合或感觉不是空的,那么结合,结合或感觉用b替换>标签如<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']);

0 个答案:

没有答案