dsuoedtom207012191 2018-02-12 20:53
浏览 73
已采纳

从PHP输入文本字段中删除某个字符串,然后将其保存到MySQL数据库[重复]

This question already has an answer here:

What I want to achieve: I want to use a simple PHP form to send data to a MySQL database. However, when the input contains a certain string, I want to remove it before it is saved in the MySQL database.

Example: input is 'https://www.google.com', but I want to remove the 'https://' part, so only 'www.google.com' is saved in the database.

</div>
  • 写回答

1条回答 默认 最新

  • dongwo2772 2018-02-12 20:55
    关注

    You can use str_replace() to remove the parts you don't want:

    $input = 'https://www.google.com';
    $replaced = str_replace('https://', '', $input);
    
    echo $replaced;
    

    If you want to replace multiple values in one pass, you also do that (this will remove http://, https:// and ftp://):

    $unwanted  = array("http://", "https://", "ftp://");
    $replace   = array("", "", "");
    
    $replaced = str_replace($unwanted, $replace, $input);
    

    See: https://secure.php.net/manual/en/function.str-replace.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决