$str = 'answers[0] = "Love it"; answers[1] = "Hate it."; answers[2] = "Doesnt care"; answers[3] = "Like it";'
どうすれば配列に変換できますか?
$str = 'answers[0] = "Love it"; answers[1] = "Hate it."; answers[2] = "Doesnt care"; answers[3] = "Like it";';
preg_match_all('/"(.*)";/U', $str, $matches);
$arr = $matches[1];
var_dump($arr);
;
セミコロン ( )の後に新しい行を追加できる場合は、parse_ini_string()
関数を見てください。
$str = str_replace(';', "\n", $str); // <- add them in the source if you can
$array = parse_ini_string($str);
$str = 'answers[0] = "Love it"; answers[1] = "Hate it."; answers[2] = "Doesnt care"; answers[3] = "Like it";';
$chunks = explode(';', $str);
for ($aa=0;$aa<count($chunks);$aa++)
{
$chunks1 = explode('=', $chunks[$aa]);
$myArray[]=$chunks1[1];
}
このようなもの?
<?php
$str = '$answers[0] = "Love it"; $answers[1] = "Hate it."; $answers[2] = "Doesnt care"; $answers[3] = "Like it";';
eval($str);
print_r($answers);
?>