我正在尝试查找和替换PHP / MySQL的功能,我正在做的第一件事是在页面上显示数据库中的所有数据,然后显示相同的内容。下面是我用来做同样的查询:
'SELECT "office_phone" as col_name, id, office_phone as search_string, trim(replace(concat(" ",LOWER(office_phone)," ")," '.$find.' "," '.$replace.' ")) as replace_string FROM `employees` WHERE ( office_phone like "'.$find.' %" OR office_phone like "% '.$find.' %" OR office_phone like "% '.$find.'" OR office_phone LIKE "'.$find.'")';
现在,如果我发现字符串为' Raj'它将显示所有字段都有来自列" office_phone" ...现在我想将找到的字符串作为粗体(仅找到字符串),例如Raj办公室号码是123456789 ..在此仅#39 ;拉吉'应该大胆..任何人都可以请快速帮助...
提前感谢...
答案 0 :(得分:0)
这应该做你的工作。 如果您想使其区分大小写,请使用:
str_replace
insted of
str_ireplace
<!DOCTYPE html>
<html>
<body>
<?php
$str="hello this is a good book. Hello, did you like the book. helloare you there?";
$strrep="hello";
$str = str_ireplace($strrep,'<b>'. $strrep.'</b>',$str);
echo "$str";
?>
</body>
</html>
答案 1 :(得分:0)
$string = "I am trying a find and replace functionality for PHP/MySQL, and the first thing what i am doing is displaying all the data from database on a page and then display the same. below is the query i am using to do the same";
$searchingFor = "/" . $searchQuery . "/i";
$replacePattern = "<b>$0<\/b>";
preg_replace($searchingFor, $replacePattern, $string);