2014-12-26 43 views
1

我正在嘗試查找和替換PHP/MySQL的功能,並且我正在做的第一件事是在頁面上顯示來自數據庫的所有數據,然後顯示相同。下面是我用來做同樣的查詢:如何將樣式應用於從MySQL數據庫中提取的數據php

'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.'")'; 

現在,如果我找到字符串爲「拉吉」,它會顯示所有的領域都拉吉從列「office_phone」串..現在我想打發現字符串爲粗體(只發現字符串),如Raj辦公室號碼是123456789 ..在這隻'拉吉'應該得到大膽..任何人都可以請快速幫助...
在此先感謝...

+1

這基本上只是「將樣式應用到HTML發出的任意塊」 +「選擇搜索字符串」。相應地解決;這個問題有點奇怪。 –

+0

其實你可以創建樣式標籤到你正在獲取的特定內容,例如<?php echo $ content;?> .....希望這樣會清楚你的問題 –

+0

這個我已經試過了,這使得我的完整句子/內容爲粗體,但是我只想要一個特定的字符串來獲得大膽 –

回答

0

這應該做你的工作。 如果你想讓它區分大小寫然後使用:

str_replace 

insted的的

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> 
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); 
相關問題