joomla CMS의 제한 때문에 제품 페이지 (케이크 용)의 양식에 필드를 추가 할 수있는 방법을 생각해야했습니다.경고없이이 배열을 반복하는 방법
그래서 다음을 생각해 냈습니다.
이 내 시작 문자열입니다
||
Taart grootte*30cm:40cm:50cm
|Kleur*rood:blauw:groen:wit
|Optie 3*optie1:optie2:optie3
내가 처음 productpage의 나머지 부분에서 내 사용자 정의 필드를 분할 ||
폭발. 그런 다음 나는 각각의 사용자 정의 필드를 분리하기 위해 |
을 폭발시키고 필드 이름에서 선택 옵션을 분리하기 위해 *
에 대한 결과를 폭발시킵니다. 모든 것이 잘 작동하지만 이제는 :
에서 폭발하여 서로의 옵션을 구분하고 싶습니다.
변수 $lines
에 필요한 정보가 포함되어 있습니다. 배열은 다음과 같습니다
Array ([0] =>
Taart grootte [1] => 30cm:40cm:50cm
) Array ([0] => Kleur [1] => rood:blauw:groen:wit
) Array ([0] => Optie 3 [1] => optie1:optie2:optie3
)
내가 키 [1]
(옵션) 만 데이터가 필요하지만. 내가 사용할 수 없습니다
foreach($lines[1] as $result){
}
을 그것을 제공하기 때문에 : Warning: Invalid argument supplied for foreach() in ....
어떻게 데이터가 나를 위해 가능한 수 있도록 내가 옵션을 분할 할 수 있습니다?
foreach($lines as $result){
$resultaat = explode(':', $result);
}
foreach($resultaat as $final){
$finalvar .= $final;
}
echo $finalvar;
그러나 그 결과가 이것이다 : 그들은 단지 한 번 문자열에있는 동안
같은 옵션은 여러 번 표시
나는 다음 시도했다.내 전체 코드 : 답변에 대한 추가 정보는
<?
// Functie om alles te deleten tussen de aangegeven values (brackets in deze code)
function delete_all_between($beginning, $end, $string) {
$beginningPos = strpos($string, $beginning);
$endPos = strpos($string, $end);
if ($beginningPos === false || $endPos === false) {
\t return $string;
}
$textToDelete = substr($string, $beginningPos, ($endPos + strlen($end)) - $beginningPos);
return str_replace($textToDelete, '', $string);
}
// Explode the fulltext on ||
$explode = explode('||', $taartcr[0]['fulltext']);
if(strpos($explode[1], '[') == false){
echo '';
echo $explode[0];
echo '';
// Explode fulltext after || on commas
$explode2 = explode('|', $explode[1]);
$lijst .= '<div class="form-group">';
foreach($explode2 as $list){
\t $lines = explode('*', $list);
foreach($lines as $result){
\t $resultaat = explode(':', $result);
}
foreach($resultaat as $final){
\t $finalvar .= $final;
}
echo $finalvar;
// echo $finalvar;
// echo '<pre>';
\t // // print_r($resultaat);
// echo $resultaat;
\t // echo '</pre>';
\t if($list[0] != ''){
\t \t $lijst .= '
\t <i class="fa fa-birthday-cake cbx-contact-icon"></i>
\t <select required="" placeholder="'.strip_tags($lines[0]).'" id="cbxname" class="form-control cbxname cbx-form-control" name="cbxname">
\t <option value="" disabled selected>'.strip_tags($lines[0]).'</option>
\t '.$resultaat.'
\t </select>
\t \t ';
\t }
}
$lijst .= '</div>';
}else{
$string = $explode[1];
$nobrackets = delete_all_between('[', ']', $string);
echo '<div class="col-md-6 wow fadeInUp" data-wow-duration="2s">'.strip_tags($explode[0]).'</div>';
echo '<div class="col-md-6 wow fadeInUp" data-wow-duration="2s">'.strip_tags($nobrackets).'</div>';
}
echo $lijst;
?>
편집 :
<?php
$lines = explode('||', $taartcr[0]['fulltext']);
$lines = end($lines);
$lines = explode('|', $lines);
$options = [];
foreach ($lines as $line) {
$result = explode('*', $line);
$name = trim($result[0]);
$values = $result[1];
$options[] = [
'name' => $name,
'values' => array_map('trim', explode(':', $values)),
];
}
foreach($options as $field){
$options1 = $field['values'];
foreach($options1 as $option){
$test .= '<option>'.$option.'</option>';
}
$fields .= '
<div class="form-group">
<i class="fa fa-birthday-cake cbx-contact-icon"></i><select required="" placeholder="'.$field['name'].'" id="cbxname" class="form-control cbxname cbx-form-control" name="cbxname">
<option value="" disabled selected>'.$field['name'].'</option>
'.$test.'
</select>
<label for="cbxname" class="error valid" id="cbxname-error"></label>
</div>';
}
echo $fields;
?>
여기에 문제를 복제하십시오. http://phpfiddle.org/ – Ionut
@Ionut 하드 코딩 된 문자열을 사용하여 스크립트에서 사용하고 있지만 스크립트를 실행하면 PHP 코드가 PHP처럼 보이지 않습니다. 설치되어 있습니다. 또한 공유 할 수있는 링크를 얻을 수있는 방법을 모릅니다. – twan