Forum Moderators: coopster
And for those unfamiliar with the term, here's part of the definition from the Wikipedia:
Spaghetti code is a pejorative term for code with a complex and tangled control structure,
In other words it is inelegant, difficult to understand for anyone who takes over a project, difficult to maintain. It is likely to be inefficient, but may in fact be very efficient if only anyone could figure out how it worked.
Top 100 Signs That I Am Writing Spaghetti Code in PHP
100. I have no idea where this constant is defined.
99. I have echo stmts littered throughout my code.
98. There is an error but it isn't handled, and I can't find it to figure out what's wrong.
23. And the last line of your codes is:
ini_set(max_execution_time,"30");
?>
20.
you include a file that includes the original file...
<!-- file1.php -->
<? include("file2.php"); //other stuff?><!-- file2.php -->
<? echo "stuff"; include("file1.php");?>
That's ridiculous code. I would never do that! No way. I prefer
<!-- file1.php -->
<? include_once("file2.php");?><!-- file2.php -->
<? include_once("file1.php");?>
Rock solid that way.
Tom
I use a page-calling script (php?page=somedullpage)
The thing is, ALL my templating and other includes have to be done in the page being called just so I can specify the title of the page.
That, to me, is probably making a mountain out of a molehill... but not figured out a better way of doing it yet.
you have so many custom fucntions that you try to redifine the nl2br function
Using info in these forums I did just that. I now have a very nice nl2p function.
Why generate <br>'s when proper markup calls for <p>'s?
I'd give credit to whoever offered the original code snippet, but I can't remember now who it was. :(
function nl2p($html)
{
// Use \n for newline on all systems
$html = preg_replace("/(\r\n¦\n¦\r)/", "\n", $html);
// Only allow two newlines in a row.
$html = preg_replace("/\n\n+/", "\n\n", $html);
// Put <p>..</p> around paragraphs
$html = preg_replace('/\n?(.+?)(\n\n¦\z)/s', "<p>$1</p>", $html);
// convert newlines not preceded by </p> to a <br /> tag
$html = preg_replace('¦(?<!</p> )\s*\n¦', "<br />", $html);
return $html;
}
WBF
(aka the answer to the question "Why does this function return different results for the same input on different pages?")