Priya
Priya

Reputation: 165

using php to do this type of job

i have this type of links in my database and its in millions

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

i want to convert this link to this link

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

i know with one line of sql replace i can achieve first part.i.e upto this part i dont have any issue http://fo.website1.com/image/ it can be easily done with

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

but i am more concerned about next part how to achieve that

that number ranges from 1 to 10000000 and for every number i have created subfolders after every 2 digit/

for example 343433 will go in 34/34/33 like that 6456454 will be 64/56/45/4

any idea how can i achieve this

i have divided like this

  $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);

want to replace website1 numbers with the desired numbers as given above and dont want to touch others

   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]

Upvotes: 2

Views: 146

Answers (1)

Alejandro Urbano Alvarez
Alejandro Urbano Alvarez

Reputation: 3346

Once you have the number (Using your code):

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

Try using str_split() instead and then join() to create the new path:

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

This will return 34/34/33 for 343433, and 64/56/45/4 for 6456454.

Upvotes: 1

Related Questions