View Single Post
Old 11-02-10, 11:24 PM   #46
Mahna Mahna
jcrox's Avatar
Join Date: Jul 2006
Location: Madison, Wi
Posts: 6,135
Default Re: Learn PHP/MySQL Feedback Thread

Originally Posted by pross View Post
nice thread so far mate, i have only one small concern so far; you are using double quotes in your variables, tho this is ok to do and works fine it can lead to hassles later especially if you want to include a double quote in the html output, for example..

$test = "hello";
$output = "<a href="">" . $test;

the above snippet will break unless the double quotes inside the html link are escaped with a \

single quotes however do not have this problem..

$test = 'hello';
$output = '<a href="">' . $test;
I'll help bring the thread back to life

Working with PHP on a daily basis in a production environment I myself can't think of any instances where the HTML that is being output is something that is anywhere near the size of this example. That just may be me but... I find that whenever I'm outputting HTML with PHP I find the easiest way to do it is via a HEREDOC.

$output = <<<HTML
$variable is a variable
{$variable[0]} is a an array element
I can use "Double Quotes" or 'Single Quotes' without worry.

The one issue rookies run into is trying to format their code to look all nice in their IDE.

This works:

$output = <<<HTML
Some content

This Doesn't:

(tab here) $output = <<<HTML
(2 tabs here) Some Content
(tab here) HTML;

Spaces of any kind prior to the closing HTML delimiter will break it.

Vin - If you need any real world examples of OOP with PHP I'd be glad to supply some. I have some pretty nifty abstraction via inclusion and dynamic class instantiation examples I could copy and paste right from work.


MSI MPower Z87 | 4770k | CNPS9900MAX-B | 8GB G.Skill 1866 | EVGA GTX760 |ThermalTake 850w | X-Fi Titanium | HAF | Asus PA248Q | Lycosa | Death Adder | Win8 Pro 64


MSI GD65 | 2500k | H50 | 8GB G.skill | GTX570 | Ubuntu 13.10


17" Inspiron | i5 | 4GB DDR3 | 500GB HDD | Win7 Pro 64

jcrox is offline   Reply With Quote