after explode how i can implode ?

Discussion in 'PHP' started by ironmankho, Nov 26, 2011.

  1. #1
    after explode how i can implode

    $data=file_get_contents('http://www.webtjax.com/test.txt');
    /////****************************************************
    $line_title=explode('true);" title="',$data); 
    unset ($line_title[0]);
    foreach($line_title as $part) {
    $line_title_temp=explode('">',$part);
    echo $line_title_temp[0].'<br />' ; 
    }
    PHP:
    Result /////

    Webmaster-1
    Webmaster-2
    Webmaster-3
    Webmaster-4
    Webmaster-5
    Webmaster-6
    Webmaster-7
    Webmaster-8
    Webmaster-9
    Webmaster-10

    now i want this type of result

    $a=Webmaster-1,Webmaster-2,Webmaster-3,Webmaster-4,Webmaster-5,Webmaster-6,Webmaster-7,Webmaster-8,Webmaster-9,Webmaster-10

    Please tell me how it is possible ?
     
    Solved! View solution.
    ironmankho, Nov 26, 2011 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    $arr = array();
    $data=file_get_contents('http://www.webtjax.com/test.txt');
    /////****************************************************
    $line_title=explode('true);" title="',$data);
    unset ($line_title[0]);
    foreach($line_title as $part) {
    $line_title_temp=explode('">',$part);
    $arr[] = $line_title_temp[0];
    }
    
    $a = implode(',',$arr);
    
    echo $a;
    PHP:
     
    danx10, Nov 26, 2011 IP
  3. windrock

    windrock Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Just replace "</ br>" with ","
    $data=file_get_contents('http://www.webtjax.com/test.txt');
    /////****************************************************
    $line_title=explode('true);" title="',$data);
    unset ($line_title[0]);
    foreach($line_title as $part) {
    $line_title_temp=explode('">',$part);
    $a .= $line_title_temp[0].',' ;
    echo $a;
    }
    PHP:
     
    windrock, Nov 26, 2011 IP
  4. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #4
    Thanks for this ... it is working :cool:
     
    ironmankho, Nov 26, 2011 IP
  5. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #5
    ok but i have one question how i can convert into unique means

    if return is

    webmaster,webmaster,webmaster,developer,designer

    but i am getting this type of error when i used

    Warning: array_unique() [function.array-unique]: The argument should be an array in code.php on line 20
     
    ironmankho, Nov 26, 2011 IP
  6. windrock

    windrock Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The argument in array_unique() must be an array.
    "webmaster,webmaster,webmaster,developer,designer" is a string. You must: $a = explode(',',$a); before use array_unique($a);
     
    Last edited: Nov 26, 2011
    windrock, Nov 26, 2011 IP
  7. #7
    $arr = array();
    $data=file_get_contents('http://www.webtjax.com/test.txt');
    /////****************************************************
    $line_title=explode('true);" title="',$data);
    unset ($line_title[0]);
    foreach($line_title as $part) {
    $line_title_temp=explode('">',$part);
    $arr[] = $line_title_temp[0];
    }
    
    $a = implode(',',array_unique($arr));
    
    echo $a;
    PHP:
     
    danx10, Nov 26, 2011 IP
  8. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #8
    Once again thanks danx10 for this
     
    ironmankho, Nov 26, 2011 IP