View string needs escape if back slash on end |
06-28-2019, 09:48 AM
(This post was last modified: 06-28-2019, 09:55 AM by InsiteFX. Edit Reason: updated )
Not sure if this is a bug or not but while working on my adminLTE 3 module
when I have an echo view like this: PHP Code: echo view('Insitefx\Admin\Views\'.$slug); All code lines after the view are red with error: (Expecting right single quote or double quote). As you can see it is quoted correctly, if I escape the back slash like this: PHP Code: echo view('Insitefx\Admin\Views\\'.$slug); Then everything is alright and it will load the Admin module view with no errors. It also works correctly using just single forward slashes. But should it also work with single back slashes? This is a Windows 10 Pro x64-bit System. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Pretty sure that's just PHP being PHP. With a backslash just before the closing single quote, the backslash is trying to be an escape character. Though it's possible it works just fine in PHP and your editor is interpreting it incorrectly. I know you need it with double-quotes, not sure with singles.
Ok, Thanks Lonnie I was just checking on it.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
You need it with both - always looks awkward but the only way to avoid escaping it.
I ended up solving it this way and it works fine.
PHP Code: echo view('Insitefx\Admin\Views'.DIRECTORY_SEPARATOR.$slug); What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
You know I think you are right because this is a Windows 10 Pro x64 system.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
So it would be best just to escape it Lonnie?
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Escaping it is a fine solution. There's really no other way to deal with a trailing backslash unless you want to define your own constant or variable, but then you'll still need to escape it:
$namespaceDivider = '\\';
This reference implies that forward slashes should not be an issue which, if true, should allow use of DIRECTORY_SEPARATOR.
On the other hand, there is this bit of advice. |
Welcome Guest, Not a member yet? Register Sign In |