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 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?