Jump to content

error: displaying php code


PC Nerd

Recommended Posts

hi guys

 

this code just started echoing itself, even though its not included at all or snything i can think of

CODE:

 


<php require("inc_files/B_A-Research_Check.inc"); 
	echo "Available Technologies: /n/n";
	foreach ($Res_Avail as $Field => $Value) {
		if($Value == "True") {
			echo " -    ".$Field."/n";
		}
	}
?>

 

 

 

i get the following displayed

 

 

 

 

$Value) { if($Value == "True") { echo " - ".$Field."/n"; } } ?>

 

 

 

does anyone have any suggestion on how to fix this???

 

 

thankx

Link to comment
Share on other sites

The opening php tag is "<?php" not, "<php".

Also, /n won't print a new line, it should be \n

 

Try it now this way:

<?php

require("inc_files/B_A-Research_Check.inc");
echo "Available Technologies: \n\n";
foreach ($Res_Avail as $Field => $Value)
{
if($Value == TRUE)
{
	echo " -    ".$Field."\n";
}
}

?>

 

Orio.

Link to comment
Share on other sites

And btw :

 

echo " -    ".$Field."\n";

 

Stop using " when u dont need it.

Learn the basics before you start programming.

 

When u echo with "  ", php looks through your string for variables, hence works slower.

 

echo " -    $Field\n";

 

would give you the same result as above, but

 

echo ' -    '.$Field."\n";

 

will work faster, and is the correct way to do it.

Link to comment
Share on other sites

And btw :

 

echo " -    ".$Field."\n";

 

Stop using " when u dont need it.

Learn the basics before you start programming.

 

When u echo with "  ", php looks through your string for variables, hence works slower.

 

echo " -    $Field\n";

 

would give you the same result as above, but

 

echo ' -    '.$Field."\n";

 

will work faster, and is the correct way to do it.

 

All the following are acceptable:

<?php
echo " -    ".$Field."\n";
echo " -    $Field\n";
echo " -    {$Field}\n";
echo ' -    ' . $Field . "\n";
?>

 

While it is good practice to use single quotes when you aren't parsing variables within your string, it is not incorrect to do so.

Link to comment
Share on other sites

While it is good practice to use single quotes when you aren't parsing variables within your string, it is not incorrect to do so.

 

I can't think of a single good reason why u should use double-quotes. But by all means, it's not illegal.

Link to comment
Share on other sites

I can't think of a single good reason why it's a viable discussion.  The person asked for help not flames.  Learn forum etiquette before posting please. 

 

Also, have you actually benchmarked the differences in string parsing with different arrangements of quotes?  The difference when I've done so in the past is almost negligible.  I will point out that I'm a performance, efficiency, and security freak so I tend to test as many of these theories out as possible for myself.  Still, regardless of it being almost negligible, I tend towards the most efficient option performance-wise.  You need it if you ever get slashdotted or the like ;) lol

 

Just a small thing to wonder...

"Learn the basics" - I would have thought that was why they were here?

 

Dest

Link to comment
Share on other sites

I can't think of a single good reason why u should use double-quotes. But by all means, it's not illegal.

 

Well, let me give you some to consider, then ;) ... first off, if you want your code to be easily legible, it is an extremely good practice to contain your variables within your string declarations instead of breaking in and out of quotes. The added characters, while negligible in smaller scripts, can start adding up to a marked difference in file size if you get into the practice of doing this for every single variable within strings. Consider larger applications that may have thousands of lines of code parsing the strings... adding unnecessary characters to the script doesn't help anything. Finally, the differences in timing are so negligible, you are usually better off writing for code clarity than worrying about microseconds of time difference in parsing. Review some of the following discussions if you still have questions, and feel free to run your own benchmark testing on time if you don't believe me.

 

http://www.thescripts.com/forum/threadnav3954-2-10.html

http://www.weberdev.com/get_example-3750.html

http://www.webmasterworld.com/php/3095627.htm

http://www.webmasterworld.com/forum88/3253.htm

http://whirlpool.net.au/forum-replies-archive.cfm/663244.html

 

Conclusion: in every case, the conclusion is that it really comes down to preference. You should, if possible, train yourself to use single quotes when there are no variables involved, but when you are introducing variables into the mix, it is not worth the effort involved to pain yourself with breaking in and out of strings to include variables. As one of the above threads mentions, though, you've got to keep from using standalone '$' that are not escaped appropriately or tied to a variable name, or your string execution time significantly increases.

 

Just a small thing to wonder...

"Learn the basics" - I would have thought that was why they were here?

Extremely well said, Destruction ;)

Link to comment
Share on other sites

Well guys, the intention by my post was not to flame, but to point out some of the "basics".

In the example included, swapping double with single quotes did nothing else but to improve the coding. No added characters and a slight performance and readability gain. I simply feel it important to point out such things now and then, not only for the current poster, but for all that read the posts.

I see no harm in this, only gain. Nowadays, php coding is, in my opinion, slipping out of control concerning coding standards. A large and complicated site/application written in php is doomed to end up badly written unless one starts to take small things into consideration. I see badly written code in this forum in most topics, and very few people that points it out for the writer.

Though the code is not "incorrect" it's not good either.

How about pinning a "coding standards"-topic if this is a forum for learning the basics?

Link to comment
Share on other sites

I agree that coding standards are lacking, but I'm not going to support suggested "standards" that are not founded on sound reasoning, either. True, your initial post didn't suggest character addition, and neither did any of my initial suggestions. We're all aiming for the same goal here (at least I hope we are), so there's no need to get defensive. I hope you have the same dedication to standards that you claim to be pushing, and if so, you will see the reasoning behind the posts I linked to, and you will understand the spirit of my responses thus far. You stated, and I quote, that you can't think of a single good reason why u should use double-quotes, and I simply provided some reasons for you to consider. I never attacked your initial post or suggestion. In fact, if one is adamant about separating the variables from the string declarations, they should indeed follow your suggestion; however, we would be remiss in our tutelage if we didn't attempt to inform users of the different options available to them.

 

This said, please don't assume that I was attacking your post; on the contrary, I was simply trying to add to the understanding provided. I also agree 100% with your assessment of badly written code being presented over and over again in these forums, and I'll address your suggestion about a pinned Coding Standards topic with the other mods/admins, too. I believe that is an excellent suggestion.

Link to comment
Share on other sites

We are both reasonable people, i think :-)

No "attacks" registered, nore any 'launched' :-)

 

Just the typical forum/mail - problem, that people read too much in between the lines ;-)

I try to write my lines so that they arent interpreted as either flaming or defensive, but I never seem to manage it fully.

Maybe I should have picked a post where the code was in more need of attention than this one, and I apologise to the initial poster on behalf of me (and probably obsidian/destruction ) that we "hijacked" your thread with this discussion.

 

I'll read your linked threads, obsidian, and there's probably lots of good concideration there. I almost cant wait, as i love theese discussions :-)

Link to comment
Share on other sites

We are both reasonable people, i think :-)

No "attacks" registered, nore any 'launched' :-)

Agreed (thankfully) ;)

 

I try to write my lines so that they arent interpreted as either flaming or defensive, but I never seem to manage it fully.

Indeed, I seem to have that same problem... LOL

 

I, too, apologize for the "hijacking" of this thread, but I think that some very good information was brought to light through it as well.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.