Reputation:
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),....
Upvotes: -1
Views: 32
Reputation: 612
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);
Upvotes: 1
Reputation:
$tags = explode(',',$new);
foreach($tags as $key) {
if ($key !== "")
{$sp[] = $key;}
}
I did the above to solve me issue.
Upvotes: 0