How can you solve equations in PHP? - php

I'm looking for a generalized equation solver in PHP. This could either be in the form of in-built functionality, a library, or even integration with another language if it comes to it. I am even comfortable with a joint solution that involves some combination of the above. I need this for an educational website on which I am working.
Let me give a series of equations that I would ideally expect such a solver to deal with:
x+5=8 => x=3
x^2=5 => x=+/-sqrt(5) [exact solution in terms of sqrt, ln, or whatever] AND
x=+/-2.236 [approximate solution to certain number of digits]
x+y=-3 [solve in terms of y] => y=-x-3
x^2=-5 => x=+/5i
x+y=3 and x-y=3 => x=3, y=0
I hope this is not a bridge too far. If so, I'll build the functionality as each problem comes in-house, but if anyone knows of the proper library for such a set of problems, I would greatly appreciate it.

Check out Sage, from their website:
Sage is a free open-source mathematics software system licensed under the GPL. It combines the power of many existing open-source packages into a common Python-based interface.
Mission: Creating a viable free open source alternative to Magma, Maple, Mathematica and Matlab.
Sage has an AJAX-based notebook interface, that is probably as good as an API that you can use from PHP.

First: your math solutions are wrong.
x+5=8 evaluates to x=3
x+y=-3, y evaluates to -x-3
etc.
To do the math: make an API call to Wolfram|Alpha.
Seeing as this is an educational venture, I would highly suggest that you do not create your own product and rely on third-party software. I would personally go with Wolfram Mathematica, and probably their pre-college solutions or go with Web Mathematica for web interfaces.
Note about Web Mathematica: it uses JSP or Java Servlets for it's back-end technology. More about specific technical details for Web Mathematica will be helpful.

Related

Basics for creating a Wiki-like web application?

I need to implement wiki-like functionality within a website.
Problem is that I am not fully aware of what it might require and therefore predict a long set of refactoring till I actually nail a good version.
I tried looking for some guidelines, but haven't found much.
Any ideas? Help would be wonderful
There's an industry standard there. If it was me and I was called upon to write a technical requirements document for a new Wiki, I'd start with the features page of Wikipedia. Then, I'd attempt to use the tools in a dev operation, determining the strengths and weaknesses of the implementation. Wikipedia is built for the masses, so there's certainly improvements you can make on the interface and layout that will better suit your needs if you choose to go this route.
Documentation and a roadmap is key to less factoring in development (regardless of language) If you go in without a plan, you'll inevitably cause yourself headaches and require yourself to go back to refactor. It's always better to build with a goal in mind and stick to a quality plan. Obviously, we all know in this industry that the other key is to realize that often those plans are well intentioned but woefully short, so those of us who are most able and willing to adapt are going to be the most likely to succeed.
Is there a specific reason you cant utilise an off the shelf project? DokuWiki is PHP based and easy to set up, once you deploy you then can easily alter to fit your needs if you have knowledge of PHP...
Rather than re-invent the wheel, I'd suggest you have a long look at DokuWiki. Not only does it provide a very simple method for embedding PHP within Wiki apges (I've built several applications relying on just this) its easy to extend and the rendering engine is easy to embed into your own code. An easy way to use the rendering engine is to just write your app as a DokuWiki template.
http://code.djangoproject.com/wiki/DjangoResources is listing several wiki applications for django.
You may be able to use one for your project as least as a source of inspiration.
I hope it helps
If you can live with simple wiki functionality without all the typical wiki syntax, try plugging a dooWiki into to one of your pages. What's nice is that there's no software involved and there's no third-party branding or advertising to deal with.

Selling a Script Built on a PHP Framework

There are a ton of PHP frameworks out there (i.e. Zend, Seagull, Symfony, CodeIgniter, CakePHP, Yii, Prado) that do a great job of implementing important pieces of a scalable/maintainable website, and I almost always pick one to start building client websites.
As of recently, I've started getting tired of providing constant development services to clients, and I'm looking at the possibility of writing more full-featured commercial scripts that can be resold over and over again in the hopes of finding that magical "recurring revenue stream" that you always hear about in fairy tales. Please note that I'm not talking about building extensions/plugins to CMS systems like Drupal or Joomla, but full blown website scripts.
So here's my multi-part question:
Is there any reason why I couldn't resell a script built on one of these frameworks as a full-blown turn-key solution (especially if the framework's licensing is something very flexible, like the BSD license)?
If not, why aren't others doing the same thing?
Have you ever seen a commercial PHP script that is based on a well-known open source framework?
I've wondered this for years, and no one I ask has ever really come up with a good explanation. It just seems like it is taboo to do so, and no one really knows why? I've seen commercial scripts that use third party libraries (i.e. jQuery, PHPmailer, etc), but never have I seen one built entirely on an application framework.
It really seems that a lot of people have missed the true nature of the question and even taken it as far as language debates (those never end well).
Is there any reason why I couldn't resell a script built on one of these frameworks as a full-blown turn-key solution (especially if the framework's licensing is something very flexible, like the BSD license)?
Assuming the framework license permits it then there's no reason you couldn't do this. You had mentioned Zend Framework so you may be interested in looking at Magento. While they offer a free community edition they also have a paid edition that works with the Zend Framework as well.
I recently worked with a file upload script that was offered commercially and it happened to be built on codeigniter (name escapes me at the moment).
If not, why aren't others doing the same thing?
My personal opinion is that it's a mix of quite a few factors really. The web based market for on premise applications (as apposed to SaaS) is already flooded with options and is starting to shrink in size. This makes less demand for an application that you would actually see the framework behind (with SaaS you most likely will never know what framework if any is being used).
A lot of the existing large players in the PHP market have been around for a while and already have their own code base that they have created and are familiar with. When you've spent years building your own libraries it's hard to justify moving to another framework.
A lot of the smaller players rarely educate themselves in proper application design and usually stick to procedural code. The big OOP features that exist in PHP today didn't come along until the 5.0 release. Mind you that was around 5 years ago but a lot of your programmers had started on their PHP tutorials and learning adventures before PHP5 was widely available and accepted on standard hosting accounts. As such most of our modern frameworks were not available CakePHP as an example didn't start until 2005. Zend framework wasn't around until 2007. These are all relatively new dates and I wouldn't expect to see a lot of commercial applications moving to them until the current generation of programmers that can write quality commercial applications age a bit (again just my opinion).
I have to heartily disagree with back2dos..
PHP's a solid, incredibly well used programming language for developing web apps. It can, of course, be used for commercial development and millions of people (me included) do just that. I'm not sure PHP bashing is really relevant here.
True, PHP is not compiled but if you really care about this you can use Zend Guard which can encrypt code. Personally I've always found open source code a plus point. Clients like to know they can get at the code if they really need to, it offers some reassurance.
There are lots of OS PHP apps, some great, some awful. Find a niche (like any business), something that has real demand, and develop for that.
So I think you're fine to develop commercial apps/scripts. Just make sure you give them decent support and documentation. You'll find people appreciate that and are willing to pay for it.
Finally on the point of your question, I agree they stand a much better chance of being used if they are based on an open source framework since you'll be opening yourself up to wider market. Zend Framework, as you may know, has a pretty open license which says you can sell anything you develop with it.
I think your most important question is point 2, why aren't others doing the same thing?
Well some people are. Vbulletin have been quite successful selling forum software, even though there's no end of free forum software available. I think their success can be attributed to a paid product, in part. As they're earning money, it's easy to fund further development. Open source, free projects usually require a dedicated team to keep development moving, as there's no money for motivation.
There's no shortage of turnkey solutions available on the web. eBay will have no end of $5 scripts available - they're usually rubbish and unsupported.
Where I work, we develop bespoke 'one-off' applications for our clients, but we're looking at selling the same applications to other clients as an opportunity to scale our business. In this case we're talking about large projects worth tens of thousands, but they're only sold to a handful of customers.
There's no reason why you can't sell a product for 50 or 100 dollars and make money - you'd just need to sell to 10, 100 or 1000 customers to start making a living from it.
And to succeed over the free open software? Produce something that isn't already available, or do something much better than what's available for free.
Finally, another model you may want to consider is software as a service. Take a look at Basecamp (37 signals) for example. Their product is not open source, you can't download it, but you register online and pay something like $10 for their lowest end offering per month.
They don't have to give out source code, and they have a solid recurring revenue stream. They have tens of thousands of accounts.
Yes of course you can sell it.
Most people don't just sell the scripts as normal people and businesses don't know what to do with them and so require a developer to install and configure the script. Developers won't then buy the script if there is an open source/free alternative. If the script performs a valuable task that is often done, then somebody is likely to copy it and create an open source version.
Your key to selling PHP code is to sell it as a service. This could either be the installation and configuration of it (like most web design/development agencies) or an on-demand version of it (think of any online business app).
My company writes and builds a lot of PHP software for businesses and as we get new clients and solve new problems we write our code in re-usable classes which we can then package up and sell to other clients without any further coding - which I assume is what you are trying to do. It's all possible, it just takes time and planning to write the software to make it re-usable for other projects.
Well in this case I think that codeigniter will be the best option because:
Don't need console access to configure
You just have to configure Database Connections
Fast, MVC, Cache, Logs, Good Documentation
Runs in PHP4, must of the people that buy this scripts have server restrictions to Upgrade PHP
Best Regards,
Pedro
As a PHP developer for over 5 years and selling scripts I never tried to developed a commercial script with a framework.It is just because Im not a good fan of any PHP framework.
Someone can say if you don't use framework you are a amateur as a developer.But I think its the a way any developer has rights to choose.
I think some companies don't use frameworks just because they just dont like to say this script based on 'ABC' to the customers.They want to boast about their scripts and only they can developed something like that.
I event seen any commercial web script that used any frameworks so far.
I can think of one reason against it: piracy. If your script is something a bunch of framework guys want, it will be pirated. If it is only for a rich niche, you can avoid this, but then you aint going to get any fairy-tale income.
It's not in the open source spirit of PHP. The trend is to give it away and then bill for the service. You might be better at marketing your script as such, and just charge people after they consult you and you hand them a script download and a manual.
i think, these are the key reasons, why it is not done:
the point of PHP was never building commercial applications (the original acronym means "Personal HomePage") ... it is an insecure, inconsistent language ... there are quite some good PHP frameworks ... nevertheless, the language is ... poor ... other server languages are cleaner, stricter, more secure, more powerfull, give access to a larger codebase and to better developement tools (notably java and the whole .NET stuff) ... i'd never use PHP if i had to built something really reliable ... (my favourite is this "overflow vulnerability fix" of chunk_split (line 1966)) ...
PHP is always open source ... ok, there are obfuscators, or even ways to distribute PHP in a binary form ... but the first is likely to break the code, if you do a lot of reflection/introspection, and the second usually requires some PHP extensions to be run, which is not really sexy ...
there are too many open source PHP projects around for any commercial software to succeed ... this was different before, but nowadays, you can simply get ANYTHING in PHP ... Typo3, Joomla, Mambo, osCommerce, PHPBB etc. ... frameworks as Flow3, symfony, CakePHP ... etc. ...
there are commercial sites running on PHP, but there is no good PHP software/framework i heard about, that i would pay for ... there's always a free alternative, and usually it is better ...
you will be having a hard time creating something, that is really worth buying ... and if you succeed, you will be having a huge community that will copy it, if it is worth buying ... either for personal commercial profit, or simply to provide a free solution ...
well, that's what i think ... :)
edit:
let me clarify my points
seems, i upset some PHP folks here ... that was not my intention (however i am quite disappointed, how biased you seem to be, given the fact that everyone contradicting me is a PHP developer and i seriously ask myself, what other languages you ever used) ... i myself started out with PHP on server side too and after moving through other languages, i came to see PHP in a different light ... explanation is provided ... whoever just does not want to read it, move on to point 2 ...i am not saying, PHP prohibits you from implementing a specific solution ... but it is being used to implement solutions it was never designed for ... it started out as >this< ... and it was constantly extended by many people, which produced:
an inconsistent API ... or does anyone else know a language, having a naming convention, where array_search, count and implode are all array routines? look at ruby, ecmascript or Haxe if you wanna see how beautiful core language APIs can be ... i'd say it's awfully designed ... but it's not designed at all ... it has simply been thrown together by numerous PHP contributors ... that's cool in the sense that you have a function for everything ... the point is, you probably won't find it ... ok, after a while, you will know it all ... probably ... but in other languages, for example, where arrays are objects, it does not take you long to know all core array routines ...
no real philosophy ... look at the languages mentioned above, look at Objective-C or functional languages, if you want, to see how consistent a languages semantics and philosophy can be, compared to PHP's "oh well, we'll just throw in another function, that'll solve the problem" ... also PHP arrays are the strangest data structure, i have ever seen ... something like a hyperpotent hash with internal order for keys and values ... and yet, it's not even an object ...
a lot of unsafe code (a lot of functions exposing overflow vulnerability or not being binary safe, or not escaping is documented, which could be used for XSS attacks) ... when i read an API reference, and it tells me what a function does, but the truth is, i have to take in account a lot of possibilities (long strings could crash my complete system or even inject ANY code, nullbytes could make escaping routines not work, but when printing out the string again, they disappear (this was a strip_tags vulnerability until not too long ago)), then that is what i call unreliable and dangerous ...
slow execution ... eaccelerator and similar extensions can reduce booting time signifficantly, but execution it self will still be slow ... the actual problem is, the language is far to permissive, which causes a lot of overhead ...
PHP was designed as a scripting language tying together a bunch of C functions ... it is often extended with further C functions, due to the fact that it is not the fastest language around ... this gives a nice speed up ... but how the hell do i know, whether a function is safe? who can tell me? i don't want to read through lines and lines of C to know ... so my two main points:
the API is a mess
what is behind that API can be a serious vulnerability for your application!!
in consequence, PHP is hard to trust ... i mean, i personally dislike both Java and ASP.NET, but i have to admit, they are trusted plattforms and trusted for a reason ... now problems arousing from the messy API are being solved by some frameworks ... but if a language requires a framework to wrap the core API in order to have something usable, that is a base for good, maintainable code, then something is wrong ...
how exactly do i use zend guard or ioncube on an arbitrary shared webspace?
really, best thing you can do, is write commmercial plugins for widely spread PHP software, but it seems this is exactly the opposite of what Lusid wants to do ... but hoping to find a niche, that is big enough that you don't need signifficant marketing efforts to reach you customers, that is small enough that you don't get crushed by copycats, simple enough to build as a standalone app and fits a number of other criteria that are prequisites for a commercial success, seems a little naive to me ...

How to use PHP to control on or off of light and air conditioner?

Is it possible even to do this kind of things?
EDIT
Can someone provide a "hello world" demo to try out?
X10/Insteon are good bets. I have seen that both of them have developer kits. You have to at least but some modules for the appliances/outlets you wish to control. I would stay away from the AC unit and just buy a programmable thermostat ;) In the end, you're going to have to do research and buy some interface hardware and control modules. X10/Insteon is probably the cheapest way to get to you goal.
Begin rant:
I have personally used X10 and it was pretty easy to use, simple serial port/com port interface to trigger lights. I don't have the code anymore, besides I feel like you're looking for a copy-n-paste solution without thinking about the problem. Even if there is an API in Java/C/C++/Python/etc... you can find a way to invoke it from PHP. Asking a more specific question may get a more specific answer. Also, don't ask for a language you admit that you don't know.
X10 java api. And another.
SmartHome - everything related to home automation.
Most if not all digital I/O cards for PCs are controlled through an interface written in C. Then most of those offer a library so you can control the boards through software you've written. Since you are able to make extensions for both of those languages in C, you could indeed write a Java or PHP wrapper around a C library for a digital I/O card and control pretty much anything that can be controlled with a digital signal.
For instance, Google quickly turned up the HW-Group IO Controller with libraries in Java and PHP (among others) and with 8 in, 8 out DIO.
It is. Google X10 - a protocol for cumunicating with things like lights and appliances.
X10 devices can be used for example to control Lava Lamps for extreme feedback when doing continuous integration. There is plenty of literature on this subject on the net. Have a look at the X10 CM17A API and Bubble, Bubble, Build's In Trouble for a real world use case.

ColdFusion/PHP Compatibility

Hey I have a question regarding the compatibility of ColdFusion and PHP.
We built a community website which is based on ColdFusion. Is it altogether possible to add features such as blogs, and other community features to our website in PHP?
I mean to combine both PHP and ColdFusion together.
Thanks very much for the help!
I think it can be done, if you're using ColdFusion 8. I know that Sean Corfield has a project on RIAForge doing this sort of thing, and there are a string of posts on his blog, starting with this one:
http://corfield.org/blog/index.cfm/do/blog.entry/entry/ColdFusion_8_running_PHP
All of this being said, it will be easier to integrate products from the same core language. There are hundreds of open source options for different things in ColdFusion. RIAForge.org is a good place to start.
Yes, it's possible. You would have to probably integrate the PHP application's session management into your Coldfusion application's session management.
I recently did that with a PHP shopping cart into Coldfusion because I didn't have the time or resources available to get the same results in Coldfusion -- often the great and polished pieces in CF can cost some money, and with PHP its a gamble or a time pit to get it to dance how you want.
Second, there might already be blogs, forums, etc that suit your needs made in Coldfusion. Check them out. You might be able to stay more towards one platform. Chances are you might want a PHP solution because it has addons or something else that you don't want to program.
I like your best-of-breed approach, Coldfusion overall has a lot more commercial development than open source when it comes to large packages that are incredibly featured.
Best of luck, be sure to share what you end up doing.
Your question wasn't really focused enough to give a single direct correct answer.
We built a community website which is
based on ColdFusion. Is it altogether
possible to add features such as
blogs, and other community features to
our website in PHP?
I mean to combine both PHP and
ColdFusion together.
When you say you want to "combine" them, what exactly do you mean? They can both co-exist on a web server and both have access to the same database; so if you want both PHP and ColdFusion applications to have access to the same data, that is not a problem at all. There would be some concerns about locking and race conditions, but from an "is this possible?" standpoint, the answer is undoubtedly YES.
Sharing session, client, or other special scopes/variables from CF to PHP should be possible with some clever programming, but would be tricky. It would depend entirely on your needs and your implementation.
If you're looking for applications to add to your community, I would recommend that you try to find something in CFML that suits your needs before you go the route of attempting to mix CFML and PHP. There are tons of free open source applications including blogs and wikis written in CFML available on RIAForge, and other websites. Canvas Wiki, and Codex Wiki are solutions that focus strictly on Wiki functionality, and there are others that include Wiki functionality as part of a larger package. Searching for "blog" in the ColdFusion category on RIAForge shows no less than 6 blogging applications like BlogCFC and others, and that doesn't even include my personal favorite, Mango Blog.
I think Corfield's way is not (very) suitable for standalone apps like blogs and forums. But it can help with sharing sessions.
On the other hand, these types of software are not so good in CF world.
I'd better proposed to play with webserver settings. Can't say much about IIS, but in Apache you are typically using different handlers for .cfm and .php files. Possible problem here is index file, that can be index.cfm or index.php. In this case .htaccess rules should help.
So, tuning webserver allows to use PHP apps in subdirectories of CF application.
Additional possibility is using subdomains, this even easier to set up, that can fit your needs. Say, blog.website.com and forum.website.com
Hope this helps.
To question owner: sorry for such odd reply, I just can't comment here yet. And sorry for small offtop too.
To Ray Camden: yes I am saying that there're not so good opensource forums/blogs for CF as for PHP. I am happy to know about Galleon and BlogCFC. But if talking about features -- they in 2006 of PHP analogues, especially Galleon. BlogCFC grows and getting better fast.
Anyway, I have a suspicion that many of BlogCFC users using it because it is written in CFML. And me too, partially.
Problem is not these two applications, they can fit someone's needs. Problem is that there're no alternatives. Or maybe I am wrong here and there's lots of another cool apps of these types?
And yes. Maybe there're another amazing proprietary blogs/forums, but we're not talkin about them now right?

How to start facebook app?

Just want to know what is better way to get start developing faccebook app?Any tutorial recommnedation?And which is better to start up -php or rails?
From my experience, there is a much better support focus on PHP than on anything else. That said, there'd be no point learning PHP just to take advantage of the superior support.
Two other general points:
The official support community is really awful. The community has no expert voices and the FB staff only interject when their reputation is at stake. Your best friend is Google and your ability to extrapolate from tutorials.
The FB style of interaction doesn't really lend itself to an MVC framework. One might still save you time, but I find they get under my feet. If you need convincing on this point, may I refer you to the many cases where JSON responses are required or where FBML needs to be 'set' for the profile.
The Facebook platform isn't a whole lot of fun and your users won't thank you for your work. But it's a massive audience and a very useful learning experience.
Good luck!
Btw, you can also use ASP.NET, in which case here is how to get started:
http://www.stevetrefethen.com/wiki/Facebook%20application%20development%20in%20ASP.NET.ashx
The link includes a VS.NET starter kit which makes it very easy to get started quickly.
Start with their docs: http://developer.facebook.com/get_started.php?tab=tutorial
There are libraries floating around for lots of different languages and frameworks so I say: whatever you're happiest with is where you should start.
I've seen pretty complete FB wrapper libraries for both PHP and Ruby. Which one you should choose really depends on which language/framework you're more comfortable with.
I will say that when I was evaluating Ruby libraries recently, Facebooker seemed to be superior in terms of active development and tutorial content on the web. (Be sure to use the Facebooker project on GitHub, not the deprecated one on RubyForge.)
Can I put a shout out for Ruby On Rails with the Koala gem?
I have built a Facebook app in the last two months learning Ruby On Rails from scratch (the last programming of any kind I did was mathematical modeling for my Physics degree project in 1995 in Fortran!).
Ruby On Rails was very simple to pick up and there is a ton of help out there. There are also lots of work already done for you in the way of Ruby Gems. For Facebook I looked through them all and I found Koala the easiest to use, personally.
http://github.com/arsduo/koala/
Re: Ruby on Rails vs. PHP - whichever you're currently competent in. If neither, whichever you'd like to become competent in. Both can do what you want.
Use the Get Started tutorial on developers.facebook.com. This will suggest you use the sample code button which will give you some PHP to list your friends.
Then you can start playing with the PHP using the wiki for reference to the FQL and FBML.
PHP will be easier to start with as there are lots of samples in PHP. Rails may have advantages in the long term though.

Categories