我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

preg_replace php删除字符后

I have a URL like this : www.test.fr/dir/file.html#hello I would delete everything after the character #. I have try this /#[a-z0-9]+/

You code is almost correct, this works just fine:

$new = preg_replace('/#[a-z0-9]+/', '', 'www.test.fr/dir/file.html#hello');
print ($new);

prints:
www.test.fr/dir/file.html

You can test it here

You can explode by '#' and get the first position. Something like this:

$url = "www.test.fr/dir/file.html#hello";
$result = explode("#",$url)[0];

近期文章

  • DO-Conv中kernel composition和feature composition为什么数学上等价?
  • python第三方库的安装
  • 怎么修改安装包里面的oem信息
  • clion下载完不会弄 高校新生
  • 请问代码最后的stud[i].score[0]为什么要加[0]?
  • envi 5.6 apply mask在哪
  • 请问有用w3c/vc实现匿名凭证系统的开源项目吗
  • PG库怎么查询读写比例
  • htuple转换string
  • 页面较小时使背景更大[关闭]
  • vtkStructuredPoints画流线
  • HFSS双层微带天线仿真
  • 冒泡排序中int型与blooean型问题
  • vue 中render函数如何渲染一个keep-alive
  • 表达式print(“17%d,(a=2)&&(b=-2));”的输出结果
  • matlab对数据画出功率谱图系统提示需要参数单精度双精度。
  • VUE3定义一个组件怎么会出现这种情况
  • 创建了一个设备信息管理系统,用的链表,接下来怎么实现“保存”功能?即存到文件里。
  • K折交叉验证和CV交叉验证区别是什么
  • Laravel 5.1身份验证 - 令牌不匹配

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华