0

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.

Tracy McCormick
  • 401
  • 1
  • 7
  • 18

1 Answers1

2

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.

unalignedmemoryaccess
  • 7,246
  • 2
  • 25
  • 40
  • Thanks but when I tried your suggestion I just get a different error now "Only variables should be passed by reference (View: /var/www/html/project-css/resources/views/user/show.blade.php)" – Tracy McCormick Jul 12 '17 at 14:53
  • @TracyMcCormick updated answer for you. Btw, you should start learning PHP before asking questions like this. – unalignedmemoryaccess Jul 12 '17 at 14:55
  • Found a solution to the new error at https://stackoverflow.com/questions/4636166/only-variables-should-be-passed-by-reference – Tracy McCormick Jul 12 '17 at 14:55