English 中文(简体)
PHP用户进入数据问题吗?
原标题:PHP user entered data problem?
  • 时间:2010-08-02 01:01:29
  •  标签:
  • php

Okay, 当用户进入数据库的标签时,我通过使用ma,排除了超文本元素和单独的标签, 但是,出于某种原因,如果一个用户输入以下数据,那么,我把一个空洞的数值连同其他标签一并输入数据库。

<html>,tag2,tag3,tag4 //an empty value is entered
,tag2,tag3,tag4 //this will also enter an empty value

html标签将被剥夺,但一个空洞的价值被输入数据库,我如何阻止这种情况发生?

我认为,这与我守则的这一部分有关。

$tags = explode(",", $_POST[ tag ]);
问题回答

提 出

array_filter( //remove elements that evaluate to FALSE (includes empty ones)
    array_map( trim , //trim space around tags
        array_map( strip_tags , //remove html tags from the... tags
            explode(",", $_POST[ tag ])))); //separate on comma

Here s a link to a function that ll remove the empty elements in a PHP array: http://www.bitrepository.com/remove-empty-values-from-an-array-in-php.html

这将消除空白标签:

$tags = explode(",", $_POST[ tag ]);
$new_set  = array();

foreach ($tags as $tag){

  if ($tag ==   ){

    $new_set[] = $tag;
  }
}

$tags = implode( , , $new);

// now store $tags into your database.

清除所有空阵元素。

 foreach($tags as $key => $tag) {
   if (empty($tag)) unset($tags[$key]);
 }

页: 1

explode(",", ",apple,pear,banana");

你们有这样一个阵列:

array(  ,  apple ,  pear ,  banana );

试爆功能分解,只要是 com。 共有3名女神学家,这意味着它将把雕像分为4个。 由于在显示投入的头 com上没有任何东西,这意味着第一个结果将是空洞的。

如果你不希望这样做,那么你就不得不从爆炸中清除任何空洞。 您可以为此使用阵列:

array_filter(explode(",", ",apple,pear,banana"));




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签