What would be the easiest way to take some $_POST textinput data that looks like:
Array
(
[0] => string() "The Black Keys - Gold On the Ceiling
Angeline - Blackout
Allele - Closure
etc"
)
And turn it into this:
Array
(
[0] => string() 'artist:"The Black Keys" track:"Gold On the Ceiling"'
[1] => string() 'artist:"Angeline" track"Blackout"'
[2] => string() 'artist:"Allele" track"Closure"'
etc
)
You can simply achieve this by using explode.
Code in action: eval.in
$string = "The Black Keys - Gold On the Ceiling
Angeline - Blackout
Allele - Closure
etc";
print $string;
$exploded_string = explode("\n",$string);
foreach($exploded_string as $child_string){
$array = explode(" - ",$child_string);
$output[]= "artist:\"".trim($array[0])."\" track:\"".trim($array[1])."\"";
}
print_r($output);
Hope this will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With