【问题标题】:How to Apply style to data fetched from MySQL database in php如何在 php 中将样式应用于从 MySQL 数据库中获取的数据
【发布时间】:2015-02-23 12:58:14
【问题描述】:

我正在尝试 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 字符串。现在我想将找到的字符串设为粗体(仅找到的字符串),例如 Raj 办公室号码是 123456789 .. 在此只有“Raj”应该加粗.. 任何人都可以快速提供帮助...
提前致谢...

【问题讨论】:

  • 这基本上只是“将样式应用于任意发出的 HTML 块”+“选择搜索字符串”。相应地解决;这个问题有点奇怪。
  • 实际上,您可以为您获得的特定内容创建样式标签,例如 .....希望这能解决您的问题
  • 这个我已经试过了,这让我的完整句子/内容变粗但是我只希望一个特定的字符串变粗
  • 我可以给你一个逻辑,我认为它可能会对你有所帮助.....首先分解整个字符串,然后与搜索值和分解值进行比较,然后将其与搜索值和爆炸值然后应用样式

标签: php mysql css


【解决方案1】:

这应该可以完成您的工作。 如果你想让它区分大小写,请使用:

str_replace

插入

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>

【讨论】:

    【解决方案2】:
    $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);
    

    【讨论】:

      猜你喜欢
      • 2015-10-16
      • 2021-10-03
      • 2015-09-18
      • 1970-01-01
      • 2017-03-01
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多