htmllaravel

How to remove HTML tags from a string in Laravel


Look at my output that shows some HTML tags:

Laravel website screenshot with some HTML tags visible

and this is my index.blade.php code:

  <tr>
                    <td>{{$row['policy_category_id']}}</td>
                    <td>{{$row['policy_title']}}</td>
                    <td>{{$row['version_no']}}</td>
                    <td>{{$row['policy_details']}}
                    <td>{{$row['expiry_date']}}</td>
                    <td>{{$row['file_path']}}</td>

                    <td><a href="{{action('policyController@edit', $row['id'])}}" class="btn btn-warning">Edit</a></td>
                    <td>
                        <form method="post" class="delete_form" action="{{action('policyController@destroy',$row['id'])}}">
                            {{  csrf_field()    }}
                            {{  method_field('DELETE')}}

                            <input type="hidden" name="_method" value="DELETE"  />
                            <button type="submit" class="btn btn-danger">Delete</button>
                        </form>

How to remove those HTML tags away and just showing human readable data?


Solution

  • You can use the strip_tags() function:

      <tr>
                    <td>{{$row['policy_category_id']}}</td>
                    <td>{{$row['policy_title']}}</td>
                    <td>{{$row['version_no']}}</td>
                    <td>{{strip_tags($row['policy_details'])}}
                    <td>{{$row['expiry_date']}}</td>
                    <td>{{$row['file_path']}}</td>
    
                    <td><a href="{{action('policyController@edit', $row['id'])}}" class="btn btn-warning">Edit</a></td>
                    <td>
                        <form method="post" class="delete_form" action="{{action('policyController@destroy',$row['id'])}}">
                            {{  csrf_field()    }}
                            {{  method_field('DELETE')}}
    
                            <input type="hidden" name="_method" value="DELETE"  />
                            <button type="submit" class="btn btn-danger">Delete</button>
                        </form>