htmlspecialchars()期望参数1为字符串,给定Laravel 5.6的数组 [英] htmlspecialchars() expects parameter 1 to be string, array given Laravel 5.6
问题描述
已经进行了研究,但找不到适合我问题的正确答案.
Already done a research but I don't find the right answer that fit my problem.
错误:htmlspecialchars()期望参数1为字符串,数组为给定的(create.blade)
error: htmlspecialchars() expects parameter 1 to be string, array given(create.blade)
<div class="an-single-component with-shadow">
<div class="an-component-body">
@foreach($setting as $setfield)
@if($setfield->type === 'smallInteger')
<div class"form-group" style="padding:20px">
<div style="display:inline-block">
<P><input type="hidden" name="set_id[{{$setfield->code}}]" value="{{$setfield->id}}">{{$setfield->display_name}}</P>
</div>
<div class="an-switch-box-wrapper pull-right" style="display:inline-block">
<div class="lcs_wrap">{{ Form::checkbox($setfield->code, '1', true) }}
<div class="lcs_switch lcs_checkbox_switch lcs_on">
<div class="lcs_cursor"></div>
<div class="lcs_label lcs_label_on">ON</div>
<div class="lcs_label lcs_label_off">OFF</div>
</div>
</div>
</div>
</div>
@elseif($setfield->type === 'string')
<div class"form-group" style="padding:20px">
<div style="display:inline-block">
<P><input type="hidden" name="set_id[{{$setfield->code}}]" value="{{$setfield->id}}">{{$setfield->display_name}}</P>
</div>
<div class="an-switch-box-wrapper pull-right" style="display:inline-block">
{!!Form::text($setfield->code,old($setfield->code),['class'=>'form-control','style'=>'width: 100%'])!!}
</div>
</div>
@elseif($setfield->type === 'integer')
<div class"form-group" style="padding:20px">
<div style="display:inline-block">
<P><input type="hidden" name="set_id[{{$setfield->code}}]" value="{{$setfield->id}}">{{$setfield->display_name}}</P>
</div>
<div class="an-switch-box-wrapper pull-right" style="display:inline-block">
{!!Form::text($setfield->code,old($setfield->code),['class'=>'form-control','style'=>'width: 100%'])!!}
</div>
</div>
@elseif($setfield->type === 'date')
<div class"form-group" style="padding:20px">
<div style="display:inline-block">
<P><input type="hidden" name="set_id[{{$setfield->code}}]" value="{{$setfield->id}}">{{$setfield->display_name}}</P>
</div>
<div class="an-switch-box-wrapper pull-right" style="display:inline-block">
{!!Form::date($setfield->code,old($setfield->code),['class'=>'form-control','style'=>'width: 100%'])!!}
</div>
</div>
@endif
@endforeach
</div>
</div> <!-- end .AN-SINGLE-COMPONENT -->
当我执行dd($request->all())
时,我获得了所有数据,但是当我单击提交"时,将发生错误.
When I do dd($request->all())
I got all the data but when I click submit the error will occur.
推荐答案
这不是Laravel特定的错误:
This is not a Laravel specific error:
在php文档中,如果您看到
in php documents if you see
htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
此函数接受2个参数,第一个是字符串,第二个是可选参数.
this function accepts, 2 parameters, first one is a string and second is an optional parameter.
如果要转义的字符串数组,请使用 foreach 并转义每个字符串
If you have an array of strings to be escaped then use foreach and escape each string
这篇关于htmlspecialchars()期望参数1为字符串,给定Laravel 5.6的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!