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条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作