假如我有如下字符串
(
[0] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_2.htm
[1] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_3.htm
[2] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_4.htm
[3] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_5.htm
[4] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_80.htm
)有什么好的算法可以得到他们的不同点,用(*)替代?
比如以上网址可以归纳为http://news.qq.com/newsgn/zhxw/shizhengxinwen_(*).htm
(
[0] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_2.htm
[1] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_3.htm
[2] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_4.htm
[3] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_5.htm
[4] => http://news.qq.com/newsgn/zhxw/shizhengxinwen_80.htm
)有什么好的算法可以得到他们的不同点,用(*)替代?
比如以上网址可以归纳为http://news.qq.com/newsgn/zhxw/shizhengxinwen_(*).htm
解决方案 »
- Call to undefined function imagecreatefromjpeg
- 有关webservice
- 怎么才能给这样的关联索引数组加上数字索引
- 怎样知道别人的浏览器版本
- PHP操作MYSQL数据库出错!
- 有用php做web service的过来人吗
- 如果将别人机器上的cookie文件复制到我的电脑上(假设使用相同浏览器),是不是能够登录别人的账号呢?如何防范。
- 不用xmlhttp实现的了吗?
- mysql:有熟悉set,enum类型字段的进来看看,谢谢(型如enum('是','否',)这种写法可以不?)
- PHP做到图片URL重写
- zf中控制器里设置参数变量疑问
- 在名字空间中如何使用php 的内置类?
如果是 array('hello', 'hellp', 'world'); 怎么表示? (*)(*)(*)(*)(*) ?
$url_arr = array('http://news.qq.com/newsgn/zhxw/shizhengxinwen.htm', 'http://news.qq.com/newsgn/zhxw/shizhengxinwen_3.htm', 'http://news.qq.com/newsgn/zhxw/shizhengxinwen_4.htm', 'http://news.qq.com/newsgn/zhxw/shizhengxinwen_5.htm');function get_url_diff($url_arr){
foreach($url_arr as $v){
preg_match_all("/[\d]+/", $v, $arr);
$v_arr[] = $arr[0];
}
foreach($v_arr as $k => $v){
if(!$v) {
unset($url_arr[$k]);
continue;
}
$split_arr[] = $v;
}
$t_arr = $split_arr;
$split_rand_key = array_rand($split_arr);
unset($t_arr[$split_rand_key]);
$t_rand_key = array_rand($t_arr);
$t_v = $t_arr[$t_rand_key];
//print_r($t_v);
foreach($split_arr[$split_rand_key] as $k => $v){
if($v == $t_v[$k]) continue;
$diff_key = $k;
}
$rand_key = array_rand($url_arr);
$temp_url = $url_arr[$rand_key];
$s_arr = preg_split("/[\d]+/", $temp_url);
$split_arr[$split_rand_key][$diff_key] = '(*)';
$url = '';
foreach($s_arr as $k => $v){
$url .= $v.$split_arr[$split_rand_key][$k];
}
return $url;
}
echo get_url_diff($url_arr);
可能我没有把前提描述清楚,我主要对一些url进行简单的分析就行了。如果是字符串,那就很复杂了。不讨论那些复杂的情况。