php中的sprinf可以格式化字符串的数据类型。今天遇到了想在其中输出%,可难倒我了。

$query =  sprintf("select * from books where %s like '% %s %'",$searchtype,$searchterm);

//我以为输出是这样的:select * from books where title like '% java %' ,但实际上输出会是select * from books where title like '% 

将其换成这样就可以了:

$query =  sprintf("select * from books where %s like '%%%s%%'",$searchtype,$searchterm);

//其中的%%中的第一个%用来转译特殊字符。

相关文章:

  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2021-11-11
  • 2021-07-06
  • 2021-09-12
猜你喜欢
  • 2021-07-29
  • 2022-12-23
  • 2021-07-09
  • 2022-02-08
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
相关资源
相似解决方案