Laravel explode() url 查询
Laravel explode() url query
在我的数据库中,查询输入存储为 BLOB,如下所示:
make=ACURA&model%5B0%5D=MDX&model%5B1%5D=NSX&auction%5B0%5D=BAYAUC&auction%5B1%5D=IAA+Osaka
现在在我看来,我试着去搞爆:
@foreach(explode('=', $url) as $par)
{{ $par }}
@endforeach
但是我得到一个错误:
htmlspecialchars() expects parameter 1 to be string, object given
我想输出的最终结果是这样的:
讴歌 MDX NSX BAYAUC IAA+大阪
我不明白你想做什么,但你用错了 explode()
功能。
正确的方法是array explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] )
The 3rd parameter is limit
and MUST BE AN INTEGER
which mean If limit is set and positive,
the returned array will contain a maximum of limit elements with the
last element containing the rest of string.
If the limit parameter is negative, all components except the last
-limit are returned.
If the limit parameter is zero, then this is treated as 1.
您可以使用此 php 方法进行 url 查询字符串解析:parse_str($string, $output_array);
PHP
$str = 'make=ACURA&model%5B0%5D=MDX&model%5B1%5D=NSX&auction%5B0%5D=BAYAUC&auction%5B1%5D=IAA+Osaka';
parse_str($str, $output);
// var_dump($output);
查看输出:https://3v4l.org/LLvAV
Laravel Blade 示例:
@foreach( $output as $opt )
@if( is_array($opt) )
{{ join(" ", $opt)." " }}
@else
{{ $opt." " }}
@endif
@endforeach
在我的数据库中,查询输入存储为 BLOB,如下所示: make=ACURA&model%5B0%5D=MDX&model%5B1%5D=NSX&auction%5B0%5D=BAYAUC&auction%5B1%5D=IAA+Osaka
现在在我看来,我试着去搞爆:
@foreach(explode('=', $url) as $par)
{{ $par }}
@endforeach
但是我得到一个错误:
htmlspecialchars() expects parameter 1 to be string, object given
我想输出的最终结果是这样的: 讴歌 MDX NSX BAYAUC IAA+大阪
我不明白你想做什么,但你用错了 explode()
功能。
正确的方法是array explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] )
The 3rd parameter is
limit
andMUST BE AN INTEGER
which mean If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string.If the limit parameter is negative, all components except the last -limit are returned.
If the limit parameter is zero, then this is treated as 1.
您可以使用此 php 方法进行 url 查询字符串解析:parse_str($string, $output_array);
PHP
$str = 'make=ACURA&model%5B0%5D=MDX&model%5B1%5D=NSX&auction%5B0%5D=BAYAUC&auction%5B1%5D=IAA+Osaka';
parse_str($str, $output);
// var_dump($output);
查看输出:https://3v4l.org/LLvAV
Laravel Blade 示例:
@foreach( $output as $opt )
@if( is_array($opt) )
{{ join(" ", $opt)." " }}
@else
{{ $opt." " }}
@endif
@endforeach