downloadTemp2014 2014-10-20 04:45
浏览 18
已采纳

str_replace只包含整个单词

I am trying to take a string, remove a list of words and any numbers, and then use the result in a MySQL query.

It will echo out the word I am trying to isolate, but when I place that word equal to the string, it returns false and won't query.

$remove_odonyms=preg_replace("/\b(st|street|rd|road|ln|lane|ter|terrace|ave|avenue|blvd|boulevard|ct|court)\b/", "", $search);

function remove_numbers($string) {
$num = array(1,2,3,4,5,6,7,8,9,0);
return str_replace($num, '', $string);
}
$street_only=remove_numbers($remove_odonyms);

So for the string $search="60 main street" echo $remove_odonyms is "60 main" and echo $street_only is "main".

But they won’t query, and they won’t do

if($street_only="main"){ echo "true";}

Edit: The query I am doing is

$query="
SELECT * FROM column WHERE number='$int' AND odonym='$odonym' AND street_name='$street_only'
";

It returns nothing. But when I change it to street_name="main", it returns the result I am looking for.

  • 写回答

4条回答 默认 最新

  • dongya2578 2014-10-20 04:55
    关注

    You have one extra space so you need to trim to remove space. so before query use trim() to remove space and match exact word in query.

    $street_only = trim($street_only);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作