-1

IM currently pulling some text and adding it into an array like so:

    foreach($getthesp2 as $thesp)
            {
        //  $sp[] = $thesp->textContent;
            $sp[] =      $thesp->textContent;

        }

The current output is like this:

The SP is Bubbly Bailey (5/2), Burnt Cream (4/1), Pearl Noir (5/1), Quality Art (6/1), Warm Order (8/1), Imaginary Diva (10/1), Nelson's Pride (12/1), Trending (12/1), Senora Lobo (25/1), ? The SP is Mossgo (7/2), Aaranyow (4/1), Ecliptic Sunrise (5/1), First Rebellion (6/1), Incomparable (7/1), Go Charlie (8/1), Live Dangerously (12/1), Studfarmer (12/1), Purford Green (16/1),

what i need it to do is take the string and break it up by , then add it into the array so the output would be:

The SP is Bubbly Bailey (5/2) The SP is Burnt Cream (4/1) The SP is Pearl Noir (5/1),....

3
  • What's wrong with explode()? Commented Dec 4, 2014 at 10:09
  • Try to use $sp= explode(',',$thesp->textContent); Hope this help you Commented Dec 4, 2014 at 10:10
  • i tried the above and the output is The SP is Array? The SP is Array? The SP is Array? T Commented Dec 4, 2014 at 10:18

2 Answers 2

1

Use array_map();

$sp = array("The SP is Bubbly Bailey (5/2)", "Burnt Cream (4/1)", "Pearl Noir (5/1)", "Quality Art (6/1)", "Warm Order (8/1)", "Imaginary Diva (10/1)", "Nelson's Pride (12/1)", "Trending (12/1)", "Senora Lobo (25/1)", "? The SP is Mossgo (7/2)"," Aaranyow (4/1)", "Ecliptic Sunrise (5/1)"," First Rebellion (6/1)", "Incomparable (7/1)", "Go Charlie (8/1)", "Live Dangerously (12/1)"," Studfarmer (12/1)", "Purford Green (16/1)");

function add_string($sp)
{
    // clean string
    $sp = str_replace("? The SP is ", '', $sp);
    $sp = str_replace("The SP is ", '', $sp);
    // concatenation
        return("The SP is ".$sp);
}
$sp_new = array_map("add_string", $sp);
print_r($sp_new);
Sign up to request clarification or add additional context in comments.

1 Comment

How should that help? Please add some more description…
0
    $tags = explode(',',$new);

foreach($tags as $key) {    
    if ($key !== "")
        {$sp[] = $key;}

}

I did the above to solve me issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.