dongtui8593 2013-09-04 15:51
浏览 31

需要通过php从文本文件中删除/清除垃圾字符

My script is writing to a text file so it can be cleaned of junk before being uploaded to a Mysql database. I need to selectively remove all characters that would cause a Mysql upload issue while preserving my format for uploading to the database

('column1' , 'column2' , 'column3'),

Above is the structure I need to maintain. So if my data has junk it it, I need it to convert to something that the database can read without it thinking it is code and throw an error at me and stopping the upload. So if raw data looks like

('$%^co--><``lumn1' , 'col[um]n2' , '##colFTumn3'),

I need it to look like

('column1' , 'column2' , 'column3'),

Any ideas on how to write a php code that will open file, clean it, and then put the contents back in the original file?

Basically I need it to remove everything that is not a number, letter or any character that is not found in a URL which would include the // and ? etc

  • 写回答

2条回答 默认 最新

  • du27271 2013-09-04 16:00
    关注

    use code like,

    $string = str_replace("-","",preg_replace('/[^A-Za-z0-9\-]/', '', "$%^co--><``lumn1"));
    

    and so on.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?