Page 1 of 1

Dann, Guru of PHP...

Posted: Thu Jan 06, 2011 7:37 pm
by jelkimantis
So I'm working on a project, and each page has some formatting that needs done, just basic stuff like default text, basic formatting, etc.

I'm wondering what the best way to accomplish this might be. I'm thinking about building a default_html.php file that has the basics in it (divs, basic page layout, etc)... Inclusion of theme files and references to javascript files would be in this file... My idea is that I'll just call this page whenever I'm rendering a page, and it will set things up right, and whatever I'm passing back will be wrapped in a "content" div that will then put the content in the right place, depending on what it is.

Am I thinking right, or am I blatantly stupid?

Re: Dann, Guru of PHP...

Posted: Fri Jan 07, 2011 9:42 am
by dann
Not at all stupid, this is the way to go. Seperate the presentation from the data. The simplest way to go about this is the create some files to cover the presentation in the head and body sections of a page. You may want to break down the body then to have separate header, navigation and footer. Then you can include those files into each page so if any changes are required you only have to make them in one place.

How complex you want to make this is up to you. But you are on the right track.

Re: Dann, Guru of PHP...

Posted: Fri Jan 07, 2011 5:05 pm
by jelkimantis
Ok! Awesome. Thanks for the help! I'm sure I'll be querying you more again soon. :-)

Re: Dann, Guru of PHP...

Posted: Mon Jan 10, 2011 10:38 am
by jelkimantis
So, encore!

I've got a tidy bit of code that makes me happy, but there is a problem.

I'm pulling data from MySQL, parsing it in php, and returning it to the main page through an AJAX function. While this works swimmingly, somewhere along the line my carriage returns and quotation marks are being turned into:



I've stripped slashed, but I'm not sure what else I can do. Maybe a string replace for the quotes? make them " instead? but what do I do about the carriage returns? How do I screen for those?

jsl

Re: Dann, Guru of PHP...

Posted: Mon Jan 10, 2011 1:42 pm
by dann
htmlspecialchars and nl2br maybe?

Re: Dann, Guru of PHP...

Posted: Tue Jan 11, 2011 7:49 pm
by jelkimantis
dann wrote:htmlspecialchars and nl2br maybe?
As noob as I am, tried the htmlspecialchars() and to no avail.

I'm wondering if the quotes got encoded wrong in the db somehow... It *is* a copy of a db... maybe something when horribly wrong in the encoding.

jsl

Re: Dann, Guru of PHP...

Posted: Tue Jan 11, 2011 7:56 pm
by jelkimantis
Ok, so somehow the encoding got all futzed up. I went in and replaced all the <?> messed areas with the correct symbol and the htmlspecialchars() worked fine with those changes.

Oh well... C'est la vie!

jsl