用php做这种工作

时间:2014-04-07 09:38:49

标签: php mysql sql

我的数据库中有这种类型的链接,数以百万计

http://fo.website1.com/image/2584372/600full-name.jpg

我想将此链接转换为此链接

http://website2.com/pic/25/84/37/2/600full-name.jpg

我知道有一行sql替换我可以实现第一部分。直到这部分我没有任何问题http://fo.website1.com/image/它可以轻松完成

UPDATE tableA set link= replace(link, "http://fo.website1.com/image/", "http://website2.com/pic/") 

但我更关心下一部分如何实现

该数字的范围是1到10000000,对于每个数字,我在每2位数后创建了子文件夹/

例如343433将进入34/34/33,就像6456454将是64/56/45/4

任何想法我怎样才能实现这个

我这样划分

  $c1=explode("/",$websitelink,-1);  $city1=end($c1);

  $f1=substr($city1, 0, 2);

  $f2=substr($city1, 2, 2);  

  $f3=substr($city1, 4, 2);

  $f4=substr($city1, 6, 10);

想要将网站1号码替换为上面给出的所需数字,而不想触及其他人

   Kurbaan HD Movie Wallpaper #1 way2enjoyKurbaan 1024x768 Wallpaper # 1Wallpapers[img]http://iv1.website1.com/image/6661434/600full-justin-timberlake.jpg[/img][img]http://media1.santabanta.com/full1/Bollywood%20Movies/All%20the%20Best/all-the-best-0a.jpg[/img][img]http://media1.santabanta.com/full1/Bollywood%20Movies/Do%20Knot%20Disturb/do-knot-disturb-0a.jpg[/img][img]http://media1.santabanta.com/full1/Bollywood%20Movies/London%20Dreams/london-dreams-8e.jpg[/img][img]http://iv1.website1.com/image/1661434/600full-justin-timberlake.jpg[/img][img]http://media1.santabanta.com/full1/Global%20Celebrities(F)/Hope%20Dworaczyk/hope-dworaczyk-7a.jpg[/img]

1 个答案:

答案 0 :(得分:1)

获得号码后(使用您的代码):

$c1=explode("/",$websitelink,-1);
$city1=end($c1);

尝试使用str_split()代替join()创建新路径:

$output = str_split($city1, 2);
$path = join('/', $output);

这将返回{34}的34/34/33和6456454的64/56/45/4