这可能很简单,但我找不到它.
我需要在字符串中搜索一组中文字符,并用英文单词替换它们.
所以基本上搜索一个不是az,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
Run Code Online (Sandbox Code Playgroud)
编辑:为清晰起见添加了实际示例:
<option value="http://imw1248.info/????/bamboo-cutting-board/small-cutting-boards/">English</option>
Run Code Online (Sandbox Code Playgroud)
应该:
<option value="http://imw1248.info/product-category/bamboo-cutting-board/small-cutting-boards/">English</option>
Run Code Online (Sandbox Code Playgroud)
码:
$str_start = strpos ( $switcher …Run Code Online (Sandbox Code Playgroud) 我正在使用自定义bootstrap wordpress主题.
我的头是根据Bootstrap建议创建的
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php // Loads HTML5 JavaScript file to add support for HTML5 elements in older IE versions. ?>
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you …Run Code Online (Sandbox Code Playgroud)