Php tutorial for beginners. Example code cannot be used dynamically by us.

Hi. I do appreciate thatyou have taken the time to maintain a forum. Really. Thanks. BUT

Here you have a link in the forum…
http://www.phphelp.com/forum/beginners-learning-php/helpful-guides-for-beginners-and-advanced-users/

Hi all
lately we have been having a lot of people using PHPHelp.com, but it seems we are getting more and more people saying something like “I am very new to PHP and I need help.” Some of these people don’t even have the basic understanding of what PHP is or how to use it.

And on page 4 you use the following code.
http://www.phphelp.com/php_tutorial/getting-started-with-php.php?page=4

There is no way for we - the newbies to compile and see this DYNAMIC CODE in action.
There is just not enough information.

Dynamic Content

I’m sure you’re interested in doing more with PHP than saying hello to the world. Otherwise, you probably would not be here reading about an HTML-embedded scripting language. You want a script that does something useful. Let’s go deeper into PHP by writing a Tip of the Day script. It will introduce several new functions and concepts, but you do not have to understand them all at once. It also offers an introduction to working with the file system.

[php]<?php

srand((double)microtime()*1000000);

$tiplist = file(“photo.tips”);

$ntips = sizeof($tiplist);

$rtip = rand(0,$ntips-1);

$tip = $tiplist[$rtip];

echo $tip;

?>
[/php]

While I agree there are tutorials that should be removed/rewritten I am not agreeing on this one. It works out of the box, no edits/understanding needed.

Thanks for replying and the honest comment.

Within Netbeans I created a new project to make certain that my other files did not play a part in the execution of the script.

The output in the browser is Hello.

To run this code, I need to have an array that includes some data right ?
This would be a list of sentences - tips.

I feel like I am missing something. I am reading your website on a tablet and running it on my Mac.
Maybe the tablet is not listing notes such as ‘the photo.tips file is required to run this example.’

Thanks again.

First off I should mention that I am just a user of these forums like yourself, so I don’t have anything to do with the tutorials and such.

When the tutorial says

The first line of the script opens a file called photo.tips (remember, Unix does not care about so-called "file extensions" found in Windows, so we don't need ".txt" at the end to identify it as a text file). There is no need to write anything to the file because we will just be reading and displaying a line of text from it. Using the file() function, each line of the file is read into the array $tiplist. We do not have to specify any file handles because the file() function takes a filename as an argument and returns an array as a result.. Each element of the array corresponds to a line of the file. The newline character is still attached to each string in the array. The tips file contains several tips, each on a line.

I think it’s pretty self explanatory that I should just create a file and add some lines to it, ietip 1 tip 2 tip 3 tip 4

Doing that and running the code gives the expected output.

Guess it kinda depends on the tutorial, for the beginners it would probably make sense to line it out for them. For more experienced readers it might be an idea to leave some stuff open so you actually have to think yourself while coding. It all comes down to preference I guess.

Thanks Jim. It is sort of crazy. A person can have massive amounts of stuff in their brain but there is so much more to learn and sort out. I am not a complete novice with Php. I am getting hung up on what I call are file structure issues. Won’t bore you with my background. Just thanks for responding.

I use Netbeans.
within Netbeans I created a file called photo.tips [size=12pt]using the same data as your example[/size] and saved it in the same directory as my index.php which has the original code.
I Ran the code.

Still outputting ‘hello’ in the browser’ which is really odd since that was output from another example in another project folder.
I had started with another set of tutorials.
I am up thru 77 of the 200 and got hung up on a very similar issue which lead me to phpHelp. The fopen() did not create the file and allow for me to insert names from the form by clicking the submit button in the browser.

For some reason, using files that are not Php seem to cause me problems.

Since I am on a Mac, not windows, I thought try using the the .txt extension so I saved as photoTips.txt
And ran the program… Same out out

This has to be a simply fix and I am really stuck - have been for too long.

Thanks again.

Well, if you don’t have an echo ‘Hello’; in the php file or “Hello” in the tips-list file, then you are at the wrong page/path in your browser.

Project directory called phpHelp.

Index.php inside of this directory has code.

URL: localhost/phpHelp/index.php

Sponsor our Newsletter | Privacy Policy | Terms of Service