douzhangkui2467 2013-09-25 11:32
浏览 33
已采纳

php来自用户输入和数据库的字符串

I have a problem about this strings

currently i save some strings into the database with simple insert query and cleaning the data by this code

mysql_real_escape_string($data)

i get the data from the database using a simple query

sample input

$saveString = "You're great";

saving...

Insert into . . . values (mysql_real_escape_string($saveString))

now when i get the string i get the You're great string

When i use this code

$str = str_word_count(strtolower($fromDbString), 1);

print_r($str);

It outputs:

Array
(
    [0] => You're
    [1] => great 
)

But if the string came from the users input in textbox and i use this code.

   $str = str_word_count(strtolower($fromUserInput), 1);

    print_r($str);

I get something like this:

   Array
    (
        [0] => You
        [1] => re
        [2] => great 
    )

How do i fix the string from the database to be process like the one from the users input?

I tried htmlentities() to check the values and the output was

from db You're great from input You're great

i tried to html decode the string from db but it still outputs You're great

  • 写回答

2条回答 默认 最新

  • douyinzha5820 2013-09-25 11:46
    关注

    If you want to return an array that contains all the string words you could try this instead str_word_count

    $str = preg_split("/[' ]/", strtolower($fromUserInput));
    //$str = preg_split("/[' ]/", strtolower($fromDbString));
    print_r($str);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题