doudong7256 2013-06-18 17:34
浏览 40

转义数组可以清除值

I have this loop that combines two arrays (questions and comments), i now want to escape it so i can use quotes and apostrophes in the comments fields.

$result = array();

    foreach ($questions as $key => $value){

        $value = mysqli_real_escape_string($value);

        if (array_key_exists($key, $comments)){

            $comments = mysqli_real_escape_string($comments);

            $result[$key] = "$value~ {$comments[$key]}";

        }else{

            @$result[$key] = "$value~ ";

             }

    }

For some reason mysqli_real_escape_string is knocking out the values (leaving only the delimiter (~)).

I have tried array_map / array_walk with array_keys outside the loop but it has the same effect:

$comments = array_map("mysqli_real_escape_string", array_keys($comments));

mysql_real_escape_string() for entire $_REQUEST array, or need to loop through it?

i want to check array's data with mysql_real_escape_string() function

How do you escape an entire array with mysqli_real_ecape_string? Any help would be greatly appreciated!

  • 写回答

2条回答 默认 最新

  • dongtou5557 2013-06-18 17:42
    关注

    As the name suggests, mysqli_real_escape_string() operates on strings - you can't pass it an entire array at once. You need to loop through the array and escape each element individually.

    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样