Dann, Guru of PHP...

Hey drop us a line about the show. Feel free to ask questions, provide feedback and criticism, or just ramble on about anything your little heart desires.

Moderators: snarkout, Patrick, dann

Post Reply
jelkimantis
Posts: 24
Joined: Wed Apr 30, 2008 9:19 pm

Dann, Guru of PHP...

Post by jelkimantis » Thu Jan 06, 2011 7:37 pm

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?

User avatar
dann
Site Admin
Posts: 1132
Joined: Mon Apr 26, 2004 10:55 pm
Location: Hampton, Va, USA
Contact:

Re: Dann, Guru of PHP...

Post by dann » Fri Jan 07, 2011 9:42 am

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.

jelkimantis
Posts: 24
Joined: Wed Apr 30, 2008 9:19 pm

Re: Dann, Guru of PHP...

Post by jelkimantis » Fri Jan 07, 2011 5:05 pm

Ok! Awesome. Thanks for the help! I'm sure I'll be querying you more again soon. :-)

jelkimantis
Posts: 24
Joined: Wed Apr 30, 2008 9:19 pm

Re: Dann, Guru of PHP...

Post by jelkimantis » Mon Jan 10, 2011 10:38 am

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

User avatar
dann
Site Admin
Posts: 1132
Joined: Mon Apr 26, 2004 10:55 pm
Location: Hampton, Va, USA
Contact:

Re: Dann, Guru of PHP...

Post by dann » Mon Jan 10, 2011 1:42 pm

htmlspecialchars and nl2br maybe?

jelkimantis
Posts: 24
Joined: Wed Apr 30, 2008 9:19 pm

Re: Dann, Guru of PHP...

Post by jelkimantis » Tue Jan 11, 2011 7:49 pm

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

jelkimantis
Posts: 24
Joined: Wed Apr 30, 2008 9:19 pm

Re: Dann, Guru of PHP...

Post by jelkimantis » Tue Jan 11, 2011 7:56 pm

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

Post Reply