dparivln22034 2009-12-19 07:47
浏览 14
已采纳

如何使用preg_replace在缺少这些子字符串的URL中添加“www”和“http://”?

I want to make this by the preg_replace:

$web = 'example.com';

I want the preg_replace make it http://www.example.com and if it http://example.com no problem. It should add http:// in it found in the URL.

I want do that is http:// not exist.

  • 写回答

3条回答 默认 最新

  • douna1892 2009-12-19 07:53
    关注
    preg_replace("/^(?:http:\/\/)?(.*)/","http://$1",$web);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致
  • ¥15 在使用pyecharts时出现问题
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算