Page 1 of 1

View PHP files as HTML locally when encoded in UTF-8

Posted: Wed Mar 12, 2014 2:03 am
by anivad
I'd like to be able to have the HTML parts of PHP pages rendered locally in HTML, for designing purposes and convenience (e.g. easily accessing other pages via the nav bar), but it looks like it's only possible when encoding the file in something other than UTF-8 (usually ANSI). UTF-8 encoded files get parsed as plain text.

It happens in Firefox, Chrome and IE. Is there something that I'm doing wrong, or would I just have to get used to coding blind if I want to use UTF-8?

Thanks!

Re: View PHP files as HTML locally when encoded in UTF-8

Posted: Wed Mar 12, 2014 8:22 am
by Christopher
When you say "UTF-8 encoded files get parsed as plain text" do you mean by the webserver/PHP? You editor? Something else?

Re: View PHP files as HTML locally when encoded in UTF-8

Posted: Wed Mar 12, 2014 10:00 am
by anivad
gah, I forgot to mention that. I mean by the browser that I open the file in, with the file stored locally and not on a webserver.

Re: View PHP files as HTML locally when encoded in UTF-8

Posted: Wed Mar 12, 2014 10:50 am
by Celauran
You're developing PHP without a web server installed locally? Why not install one?

Re: View PHP files as HTML locally when encoded in UTF-8

Posted: Sat Mar 22, 2014 2:41 am
by anivad
Trying to install a local webserver has been maddening; I've tried a few times, and just wasted half of today trying again, this time using the WAMPserver package instead of trying to install all the individual components on my own (that never worked and I kept getting error messages). This worked for a bit, but wouldn't parse PHP within HTML files; I searched online fixes and tried those, edited the htaccess, still nothing. Undid my edits, and now WAMP doesn't even work at all and I have no idea why. It's been extremely frustrating, basically, and I'm mad at how most of my Saturday is already gone. :(

But I guess this means that there's no way to view those PHP files as HTML locally without a local webserver, if they're encoded in UTF-8?

Re: View PHP files as HTML locally when encoded in UTF-8

Posted: Sat Mar 22, 2014 7:55 am
by Celauran
You won't be able to parse the PHP in the files without PHP and a web server installed, that's for sure. Hve you taken a look at Vagrant or PuPHPet? Barring that, if you're specific about which errors you've encountered, I'm sure there are people here familiar with WAMP setup who could give you a hand.

Re: View PHP files as HTML locally when encoded in UTF-8

Posted: Sat Mar 22, 2014 9:30 am
by anivad
It's all right - I reinstalled the WAMP server after uninstalling it, and it seems to work fine now.

Are the older versions of PHP compatible with the newer ones, though? The PHP version in my WAMP package is 5.3.13, while my remote server uses PHP 5.2.17. A few functions have been deprecated since then, so I'm updating those. Are there likely to be any problems if I develop PHP scripts locally and then transfer them to my remote server, or is it usually okay?

Re: View PHP files as HTML locally when encoded in UTF-8

Posted: Sat Mar 22, 2014 9:48 am
by Celauran
5.3 is almost end of life. 5.2 is really old and should not be used. You should inquire with your hosting provider about getting access to a newer version. There will always be some headaches when developing across versions and/or across platforms. Generally, though, these are pretty minor. Developing for 5.2 means you won't have access to namespaces, closures, traits, the DateTime object and autoloading may behave differently. That's off the top of my head, so shouldn't be considered a complete list. Take a look at the changelogs to see what was introduced after the version for which you're developing. Additionally, there are some gotchas when developing PHP apps on Windows. The big ones are case sensitivity and line endings, though I believe there are also some issues with mail.

Re: View PHP files as HTML locally when encoded in UTF-8

Posted: Sat Mar 22, 2014 10:11 am
by anivad
Thanks! Yeah, I'm thinking of changing to a different hosting provider at the end of the year, so I'll probably have to see what PHP version they're using.