duanletao9487 2015-03-25 03:37
浏览 51
已采纳

保护URL并将其存储到DB中

I'm trying to develop the best way to store a URL into a database, and make sure it has either http://www. or https://www., etc., correctly place infront of it. So if someone put in stackoverflow.com, it'd correct it to https://www.stackoverflow.com instead. That way when it echos out the url on the page and is clicked, I won't have to worry about the link breaking.

Also, the second part of this, I have tried to just straight up store a link inside a database, and sometimes it won't allow it when submitting via php/mysqli. I think it was a character or something like that, that wouldn't allow it to be stored. Should I encrypt the link and then decrypt it upon showing on the page?

I greatly appreciate the help, and none of the things I searched on google were helping, and trying to get a site for a charity done for an event for then.

  • 写回答

1条回答 默认 最新

  • duansen6750 2019-07-27 17:58
    关注

    Try this out.

    $mylink = https://www.google.com
    $stripped_http = preg_replace("(^https?://)", "", $mylink);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题