dongshan8953 2014-10-10 09:06
浏览 63
已采纳

PHP-将逗号分隔的字符串转换为Dot或Symbol分隔值,以便存储在MySql中

My current project consist of a Mysql table having 22 fields already.

I want to add a new field namely Permanent address. in the front-end its a textarea in which user will fill the following data's with either newlines or comma separated As per the standard of here, First string will House name, then Post office, then Place, then Pincode.

So I want to store it in a single coloumn namely "permanent_address". so how I store this comma/newline separated values into table field.?

Can it achieved by converting the comma/newline values into symbol ( @,#,%,&,* ) separated values, so that it can be stored to DB without violating 1st NF

enter image description here

  • 写回答

1条回答 默认 最新

  • dtpfia3334 2014-10-10 09:20
    关注

    You can use explode function to split the text into different parts. It will work like this,

    $parts = explode(",",$input);  // this will split input in array, $input will have the text input
    $street_name = $parts[0];      // gives the first part 
    

    If you want to split by both "," and new line " ", you can use,

    $parts = preg_split( "/[,|
    ]/", $input );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突