Jump to content

I am new to PHP, what exactly is it good for?


yakoup46

Recommended Posts

I have been messing around a lot with it and all I have created are some pointless, never going to be useful scripts. I have done mySql work which is very important but I was just curious if there is anything else that it is especially good for?  ;D

Link to comment
Share on other sites

Making a dynamic website, such as this forum or a blog (wordpress) or an online text-game plus many other types of websites.

 

PHP is good for pretty much any type of website you want to make that is dynamic. The best part of PHP is you do not have to pay for it to run as Apache is free, PHP is free and Linux is free. You do, however, have to pay for the space (harddrive space) and the bandwidth for the website. But as far as software is concerned the cost is very low, which is what makes PHP/Apache very attractive.

Link to comment
Share on other sites

Really I didn't get the vibe that PHP had those capabilities. Like for example look at this JavaScript i wrote:

<script type="text/javascript">

if (document.getElementById){

document.write('<style type="text/css">\n')

document.write('.submenu{display: none;}\n')

document.write('</style>\n')

}

 

function SwitchMenu(obj){

if(document.getElementById){

var el = document.getElementById(obj);

var ar = document.getElementById("masterdiv").getElementsByTagName("span");

if(el.style.display != "block"){

for (var i=0; i<ar.length; i++){

if (ar.className=="submenu")

ar.style.display = "none";

}

el.style.display = "block";

}else{

el.style.display = "none";

}

}

}

</script>

 

This script basically make it so when you click on a heading it drops a menu and that menu can drop a menu etc. and when you click back on the heading it closes everything. I tried to replicate this on PHP with no luck. Can you help me?

Link to comment
Share on other sites

Javascript is Client side scripting. Meaning that it is controlled after the page has loaded. PHP is server side. They are two different items, apples and oranges. PHP is executed on the server side and thus cannot modify the webpage without a page reload. Where as Javascript can since that is what it is used for.

 

Javascript, as such being on the client side, relies on the client allowing javascript. Where as PHP relies on the server and does not care what the client has. As such you really "cannot" replicate that, other than using CSS 2.0 to create the drop down instead of Javascript, but then again, you are using CSS, which relies somewhat on the client side given that each browser handles it a bit differently.

Link to comment
Share on other sites

[...] and Google use it [...]

 

Nope, not Google. They use Python for their web pages.

 

Anyway, I don't quite get your languages. PHP is good for making dynamic web pages. Virtually all web pages you see today will be dynamic in some way. Name your 10 (or 5) favorite web pages. All of them will be dynamic.

Link to comment
Share on other sites

So...sessions, being able to validate information without the user just circumventing the validation process, interacting with databases, and flatfile manipulation (to name a few) isn't cool enough for you?  It's not really fair to compare php to javascript.  They are 2 different languages, used in 2 different settings.

 

If you're judging it based on how flashy you can make things, then sure, it's going to be at the bottom of your list.  But that's because it's a server-side language.  If you want to look at making things flashy, that's what clientside languages are for.

 

You say that php is easy and limited, but I don't think you really understand the difference between a server environment and a client environment.

Link to comment
Share on other sites

And someone also said it's like apples to oranges, which is completely true.

 

Yes, Javascript does cool stuff. There is stuff like JQuery and other Javascript libraries that do some great things for your users experience - but you need a way to process and store that data - yes? That is what PHP is for.

 

It's limited only to what you know.  I've been dinking with PHP for years and still feel like an amateur.

 

 

Link to comment
Share on other sites

I did not mean to bash PHP. I would be lost without because i know no other way to interact with my databases. I use it very much, but just for Databases, really. But was is that flat line manipulation you spoke of that sounds interesting. Again I did not mean to lessen the value of PHP.

Link to comment
Share on other sites

oh. Is there anyway to make it search for certain words. Like all i have done so far is made it go to the file i did null for the flags part and started at -1 and went to 20 and it displayed the text. Can i make it search for a word start there and then go 20 characters more. Or can i have it search for a word and if its in the document yield TRUE or FALSE if it is not there, and if it is (TRUE) have it do another operation.

Link to comment
Share on other sites

yes.  That's what regex is for.  You would use for instance, preg_match or preg_match_all.  You would make a pattern/rules for what you want to look for, and have it look for stuff matching the patterns/rules you specify.  It can then extract what you are looking for or simply return true or false if it finds something matching the pattern, etc..

 

edit: so you would for example first use file_get_contents to get the file, then use regex functions to search/retrieve stuff.  It really depends on what you are searching for as to how complex the pattern needs to be, or what function would be best.  There are plenty of php functions that look for exact strings within other strings, etc...

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.