在PHP中怎么判断字符串中没有,在php中搜索字符串中没有的字符

本文介绍如何在PHP中查找并用英文单词替换字符串中特定的非英文字符组,通过使用`strpos`和`substr_replace`函数实现高效搜索和替换。示例展示了如何定位'.info/'后的中文字符并替换为'product-category'。
摘要由CSDN通过智能技术生成

这可能很简单,但我找不到它.

我需要在字符串中搜索一组中文字符,并用英文单词替换它们.

所以基本上搜索字符串的第一个字符不是a-z,1-9或 – ,但我找不到如何.

我目前在字符的开头和结尾使用字符串指针来实现结果,工作很好,但看起来很草率.

$str_start = strpos ( $switcher , 'start' );// get the string start

$str_start +=5;//Add 5 to it to make up for the length of search term

$str_end = strpos ( $switcher , '/' , $str_start );//find the end

$length = $str_end - $str_start;//get the length of chinese characters

echo substr_replace ( $switcher , 'product-category' , $str_start , $length );//replace with english word

编辑:为清晰起见添加了实际示例:

English

应该:

English

码:

$str_start = strpos ( $switcher , '.info/' );

$str_start +=6;

$str_end = strpos ( $switcher , '/' , $str_start );

$length = $str_end - $str_start;//get the length of chinese characters

echo substr_replace ( $switcher , 'product-category' , $str_start , $length );

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值