Fix – htmlspecialchars() expects parameter 1 to be string, array given

If you are getting htmlspecialchars() expects parameter 1 to be string, array given error, this article will help you fix the issue. Consider the example…

The post Fix – htmlspecialchars() expects parameter 1 to be string, array given appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven

If you are getting htmlspecialchars() expects parameter 1 to be string, array given error, this article will help you fix the issue.

Consider the example below:

@foreach($data->ac['0'] as $link)
    <a href="{{ $link['url'] }}">This is a link</a>
@endforeach

When you use a blade echo {{ $data }} it will automatically escape the output. It can only escape strings.  In the snippet above data $data->ac is an array and $data is an object, neither of which can be echoed as is. You need to be more specific of how the data should be outputted.

If you  if you intend to send the full array from the HTML to the controller, can use this:

<input type="hidden" name="quotation" value="{{ json_encode($quotation,TRUE)}}">

and update your controller like below:

public function Get(Request $req) {

    $quotation = array('quotation' => json_decode($req->quotation));

   }

The post Fix – htmlspecialchars() expects parameter 1 to be string, array given appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven


Print Share Comment Cite Upload Translate Updates
APA

Deven | Sciencx (2021-02-26T15:43:09+00:00) Fix – htmlspecialchars() expects parameter 1 to be string, array given. Retrieved from https://www.scien.cx/2021/02/26/fix-htmlspecialchars-expects-parameter-1-to-be-string-array-given/

MLA
" » Fix – htmlspecialchars() expects parameter 1 to be string, array given." Deven | Sciencx - Friday February 26, 2021, https://www.scien.cx/2021/02/26/fix-htmlspecialchars-expects-parameter-1-to-be-string-array-given/
HARVARD
Deven | Sciencx Friday February 26, 2021 » Fix – htmlspecialchars() expects parameter 1 to be string, array given., viewed ,<https://www.scien.cx/2021/02/26/fix-htmlspecialchars-expects-parameter-1-to-be-string-array-given/>
VANCOUVER
Deven | Sciencx - » Fix – htmlspecialchars() expects parameter 1 to be string, array given. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/26/fix-htmlspecialchars-expects-parameter-1-to-be-string-array-given/
CHICAGO
" » Fix – htmlspecialchars() expects parameter 1 to be string, array given." Deven | Sciencx - Accessed . https://www.scien.cx/2021/02/26/fix-htmlspecialchars-expects-parameter-1-to-be-string-array-given/
IEEE
" » Fix – htmlspecialchars() expects parameter 1 to be string, array given." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/02/26/fix-htmlspecialchars-expects-parameter-1-to-be-string-array-given/. [Accessed: ]
rf:citation
» Fix – htmlspecialchars() expects parameter 1 to be string, array given | Deven | Sciencx | https://www.scien.cx/2021/02/26/fix-htmlspecialchars-expects-parameter-1-to-be-string-array-given/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.