解析错误:语法错误,意外'布局'(T

编程入门 行业动态 更新时间:2024-10-27 10:32:27
解析错误:语法错误,意外'布局'(T_STRING),期待','或')[重复](Parse error: syntax error, unexpected 'layouts' (T_STRING), expecting ',' or ') [duplicate])

这个问题在这里已有答案:

PHP解析/语法错误; 以及如何解决它们? 13个答案

我正在研究一个laravel项目中的视图(完整项目可以在github上找到https://github.com/wvulibraries/rockefeller-css/tree/trying-searchy/src/project-css )我想做什么确定字符串是否包含扩展名为.txt的文件名,然后从字符串中删除路径。 只留下filename.txt。 我们正在导入一个csv文件,该文件的路径将不同。 我们想要的是将文件加载到存储中的文件夹中,让用户单击以查看该文件。 一个记录的示例是“.. \ documents \ BlobExport \ formletters \ vecr0601_concurrent_receipt.txt”。 我打算尝试使用

$filename = end(explode('\',$rcrd->$clmnNme));

但它一直崩溃视图并给出“解析错误:语法错误,意外'布局'(T_STRING),期待','或')'(查看:/ var / www / html / project-css / resources / views /用户/ show.blade.php)”。 目前的观点如下。

@extends('layouts.default') @section('content') <!-- Search engine --> @include('user/searchbox'); <!-- Separation --> <hr/> <div class="dataWrppr"> <div class="container"> <!-- Separation --> <hr/> @foreach($rcrds as $key => $rcrd) <div class="col-xs-12 col-sm-12 col-md-12"> @foreach($clmnNmes as $key => $clmnNme) @if (strpos($rcrd->$clmnNme, '.txt') !== FALSE) @php $filename = end(explode("\", $rcrd->$clmnNme)); @endphp <h4><b>{{$clmnNme}}</b>: {{$rcrd->$clmnNme}} {{$filename}}</h4> @else <h4><b>{{$clmnNme}}</b>: {{$rcrd->$clmnNme}}</h4> @endif @endforeach </div> @endforeach </div> </div> @endsection

数据库无法更改它正在用于研究,因此我无法在导入期间更改它。 任何帮助,将不胜感激。

This question already has an answer here:

PHP parse/syntax errors; and how to solve them? 17 answers

I'm working on a view in a laravel project (full project is available on github at https://github.com/wvulibraries/rockefeller-css/tree/trying-searchy/src/project-css) what I want to do is identify if the string contains a filename with a .txt extension and then strip out the path from the string. Leaving just filename.txt. We are importing a csv file and the path is going to be different for the file. What we want to to is load the files into a folder in storage and let the users click to view the file. An example from one record is "..\documents\BlobExport\formletters\vecr0601_concurrent_receipt.txt". I was going to try to use

$filename = end(explode('\',$rcrd->$clmnNme));

but it crashes the view ever time and gives "Parse error: syntax error, unexpected 'layouts' (T_STRING), expecting ',' or ')' (View: /var/www/html/project-css/resources/views/user/show.blade.php)". The current view is below.

@extends('layouts.default') @section('content') <!-- Search engine --> @include('user/searchbox'); <!-- Separation --> <hr/> <div class="dataWrppr"> <div class="container"> <!-- Separation --> <hr/> @foreach($rcrds as $key => $rcrd) <div class="col-xs-12 col-sm-12 col-md-12"> @foreach($clmnNmes as $key => $clmnNme) @if (strpos($rcrd->$clmnNme, '.txt') !== FALSE) @php $filename = end(explode("\", $rcrd->$clmnNme)); @endphp <h4><b>{{$clmnNme}}</b>: {{$rcrd->$clmnNme}} {{$filename}}</h4> @else <h4><b>{{$clmnNme}}</b>: {{$rcrd->$clmnNme}}</h4> @endif @endforeach </div> @endforeach </div> </div> @endsection

The database cannot change it is being used for research so I cannot change it during the import. Any help would be appreciated.

最满意答案

通过使用反斜杠,您可以转义字符,这就是您遇到错误的原因:

//Correct $tokens = explode('\\',$rcrd->$clmnNme); $filename = end($tokens); //Wrong $filename = end(explode('\',$rcrd->$clmnNme)); //Wrong

您还可以从代码突出显示器看到这看起来奇怪的东西。

By using backslash, you escape character and that's why you have an error:

//Correct $tokens = explode('\\',$rcrd->$clmnNme); $filename = end($tokens); //Wrong $filename = end(explode('\',$rcrd->$clmnNme)); //Wrong

You can also see this from code highlighter that something looks odd.

更多推荐

本文发布于:2023-07-27 15:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   意外   错误   语法错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!