PHP Switch Case with Include Breaks Following Code

352 Views Asked by At

My code was working before I included it in an external file.

In my main file:

switch($data){
case 'test': include_once(dirname(__FILE__) . '/test.php');
break;
}

In test.php:

<?php 
echo 'bark bark';
?>

What I get when I try to load the main file :

Parse error: syntax error, unexpected 'break' (T_BREAK) in /(......directory info removed)/mainfile.php on line 3

I have tried many different ways to reference the directory path, including the full path (public_html, etc), and nothing seems to load it. I am using Wordpress; not sure if that makes a difference.

Any ideas?

1

There are 1 best solutions below

2
On

There is a character &#65279 - 'ZERO WIDTH NO-BREAK SPACE' after your ; in include_once. You should have copy pasted from somewhere. Just remove the last character or try typing manually. This fixes!

enter image description here

Read about this here