Question

Eg. www.google.com to com.google.www

I have a full list of address to be flip over. It's all stored in "queriess.csv" How should the code be like?

<?php
$file = file('queriess.csv');
foreach($file as $line){
    list($ipadd)=explode(" ", $line);
    echo"<b>$ipadd  </b>";
}
Was it helpful?

Solution 3

Very simple. Providing all of the records have three parts, www., websitename and .ext you can explode at the . and re-order the array.

$parts = explode('.', $address);
$new_string = $parts[2] . $parts[1] . $parts[0];

OTHER TIPS

Explode => Reverse => Implode.

$string = "www.google.com";
$words = explode(".",$string);
$words = array_reverse($words);
echo implode(".",$words);

DEMO.

You could do like this..

<?php
$str='www.google.com';
$arr=explode('.',$str);
$arr=array_reverse($arr);
echo implode('.',$arr); //"prints" com.google.www

Putting it in a function for processing all your URLs

<?php

function returnURL($url)
{
$arr=explode('.',$url);
$arr=array_reverse($arr);
$arr=implode('.',$arr);
echo $arr;
}

foreach($yourURLs as $url) //$yourURLs is the list of URLs say www.google.com , www.yahoo.com ...
{
  returnURL($url); //<--- say if your url is www.google.com.. it prints com.google.www
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top