Jump to content

Is php easy?


heeha

Recommended Posts

Then you need to stop copy-pasting code and actually learn what the code does that you write.

 

Take the code that you already have and learn what each line does. And then try to alter the code slightly and check if it works as expected. Keep repeating until you have mastered PHP.

Edited by ignace
Link to comment
Share on other sites

Well, I dont copy paste, what I do i surely change them to my needs and see if that works on my server or not. But those coding given at w3schools are easy to get answers with but doing coding myself is very tough as of now. 

Link to comment
Share on other sites

actually, your title of this thread is about php, but what you are having a problem doing is programming. these are two different things. php is a programming language. putting programming language statements together so that they accomplishing something, is programming.

 

php is a fairly intuitive programming language. you can generally look at code written in php and deduce/infer what that code is doing, provided that people have used meaningful names for things like variables, form fields, database tables/columns, ... and have not used any short-cuts that magically create or alter values without explicit code or lists of data doing the creating or altering of the values.

 

programming, i.e. actually putting code together that accomplishes a stated goal, requires definition, definition, and more definition. in order to produce program logic that does something, you must first define what you are trying to accomplish/what the goal is, then what inputs you have available (even if the input is just the request to run the code), define what processing you are going to do based on the inputs, and define what result or output you are going to produce from those inputs. programming also requires that you are familiar enough with the syntax, punctuation, and spelling of the language you are using so that you can write meaningful sentences/lines of code using that language.

 

for your current thread - http://forums.phpfreaks.com/topic/297755-improper-form-working-in-php/ what you are trying to accomplish is to provide a form for entering a hostname/domain name, then display the dns records for that hostname/domain name. this is actually two separate goals/processes on one physical page, two logical pages in one. displaying the form for entering the data is one goal/process. displaying the result, after the form has been submitted, is a second goal/process.

 

for the form, what inputs do you have, what processing will there be for each of those inputs, and what result/output will you produce. inputs - along with just the request to run the code, you may (optionally) have validation errors and the previously entered form field data. processing for each of those three inputs - (unconditionally) produce a form, (optionally) format validation errors, and (optionally) get previously entered form field data. output/result - display any validation errors, display the form that you produced, and repopulate the form field(s) with any previously submitted form data.

 

so, for your form, what would applying this process this look like -

// form
// inputs - request to run the code, (optionally) validation errors, (optionally) previously entered form field data.
// processing - (unconditionally) produce form, (optionally) format validation errors, (optionally) get previously entered form field data.
// output/result - display any validation errors, display form, repopulate form field(s) with any previous form data.

// processing -
// get any previously entered form field data.
$url_value = isset($_GET['url']) ? $_GET['url'] : '';

// produce form
$form_output = "<form action='". htmlspecialchars($_SERVER['PHP_SELF']) . "' method='GET'>
Enter URL: <input type='text' name='url' value='$url_value'>
Submit: <input type='submit' name='submit'>
</form>";

// format any error messages - this example assumes that you have an array of messages in $errors (so that you can handle any number of errors, not just one.)
$error_output = '';
if(!empty($errors)){
    $error_output .= "The following errors occurred:<br>";
    foreach($errors as $error){
        $error_output .= "$error<br>";
    }
}

// output/result -
if(!empty($error_output)){
    echo "<span class='error'> * $error_output</span>";
}
echo $form_output;

for the form processing code, you would do the same. define what inputs you have, what processing you are going to do on each of those inputs, and what output/result you are going to produce from those inputs.

Link to comment
Share on other sites

Easy is a relative term. PHP is pretty straightforward, it has great documentation, and it has a massive community. It has tons of existing libraries and frameworks. To me, these qualities make it easy.

 

But if PHP is your first take on programming, then you might not think it is easy. But you're really talking about programming and not PHP specifically. You see, once you have learned the concepts of programming and understand them well, you can apply that knowledge to any programming language. Every programming language is still programming, and they all follow the same principals.

 

To a seasoned developer, PHP is easy. To a beginner, PHP is hard.

  • Like 1
Link to comment
Share on other sites

Also, PHP is extremely versatile, and has a history, and, like many programming tools, there have been / are several ways to use it.  Assuming that one programmer uses PHP the same way as another could lead to wrong assumptions and inferences when reading / trying to understand code.

For this reason a good book is often a great resource, as they will typically start with "Hello World" and gradually introduce concepts and constructs until you become "relatively competent".  I recommend books because I've yet to see an online resource with the breadth of scope and logical flow that, say, Larry Ullman's PeachPit Press books have.  There are some clunkers, however; some of them are basically printed versions of the online PHP manual, which I feel works best as a reference work rather than a tutorial (Looking at you, SAM's and possibly even at O'Reilly [although usually O'Reilly does great stuff]).  I won't offer opinions on the Wrox work as I'm friends with some of those writers, reviews are here.
 

To a seasoned developer, PHP is easy. To a beginner, PHP is hard.


I'd agree, although in large-scale projects it often seems like you need a secretary just to keep the copious notes that you need to learn a system; not particularly the fault of the OOP paradigm, or the FP paradigm, but a lot of "professional" software in PHP has shipped with rather poorly-documented code being a main feature....

Link to comment
Share on other sites

I'd agree, although in large-scale projects it often seems like you need a secretary just to keep the copious notes that you need to learn a system; not particularly the fault of the OOP paradigm, or the FP paradigm, but a lot of "professional" software in PHP has shipped with rather poorly-documented code being a main feature....

That is just a testament to how easy PHP is to pick up and build something with.

 

I would argue over the term "professional software". Just because software is popular doesn't mean that it was built by professionals. There are many, many, many horribly written PHP apps that are super popular today. Most of the forum software, most of the ecommerce software, most of the blogging software, etc. I wouldn't call any of that professional software.

  • Like 1
Link to comment
Share on other sites

That is just a testament to how easy PHP is to pick up and build something with.

 

I would argue over the term "professional software". Just because software is popular doesn't mean that it was built by professionals. There are many, many, many horribly written PHP apps that are super popular today. Most of the forum software, most of the ecommerce software, most of the blogging software, etc. I wouldn't call any of that professional software.

I'd agree re: popularity.  By the same token, if someone charges you money for the software, then they are, technically, and I think you couldn't refute that with standard word definitions, in the software business as a profession. ;)

Link to comment
Share on other sites

  • 2 weeks later...

You need to write a lot of code to get used to it. It is normal that it seems that way to you. It's like learning a language. When you have been learning it for a long time by speaking and writing and what not, you suddenly have this " feeling " of what verbs or adverbs to use without thinking.

 

Same with PHP and programming in general.

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.