doupu7651 2016-05-01 15:00
浏览 42

从具有多个条目的表单中的变量数组之前和之后剥离空格

I have a form that inputs data using explode and splits the entry into 2 fields so from

START POINTS
_3Bug_Salad 1
devinm21 1
Misfit_Eye1 3
Mrslookingfor25 3
Kaibrosky 5
sajoma 6
BRs_Ronycezar 14
UBG_Arielle 19
SG_Bluemango22 29
DJ_Habs 10
STOP POINTS

it puts into PlayerName and points which works almost perfect the only issue is when I have a space before or 2 spaces after the names it stops the code

here is the code I am using

    $Points = explode("
", $Points);
    foreach ($Points as $v)
    {
    if ($v == "") continue;
    $v = explode (" ", $v);
    if (count($v) != 2)
    die("Incorrect values in POINTS input (check spaces!)<br>");
    if (strstr(strtolower($v[1]), 'points')) continue;
    $r = mysql_query("insert into points values ('','${v[0]}', 
    ${v[1]}, '".$_POST["tourdate"]."', '".$_POST["tourtime"]."')");
    if (!$r) die (mysql_error());
    }
    echo "Points submitted Successfully";

How would I set it to trim the names so that it can only start with a alphanumeric or _ and only have one space after the name and if not remove the whitespaces

to explain better

_3Bug_Salad 1 works
 _3Bug_Salad 1 doesnt work
_3Bug_Salad   1 doesnt work

where I need all 3 to submit _3Bug_Salad to player name and
1 to points column

  • 写回答

1条回答 默认 最新

  • dqxmf02844 2016-05-01 16:17
    关注
    $v = array_filter( explode (" ", trim($v)) , "strlen");
    

    Try this.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)