Tag: PHP

String Function in PHP

nl2br(): The nl2br() function adds the tag if it finds the carriage return (n) in the text. If you text is long and at many places carriage return is present, even then the nl2br() tag will replace all the occurrence of the carriage return with tag. Here is the syntax of the nl2br() tag: [php] …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/08/string-function-in-php/

String Functions in PHP [heredoc syntax]

The heredoc syntax: In addition of the single quote and double quote syntaxex, PHP provides another way to specify a string called heredoc syntax. This syntax turns out to be a extremely useful for specifiying large chunks of variable-interpolated text, because it spares you from the need to escape internal quotation marks. It is especially …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/08/string-functions-in-php-heredoc-syntax/

Read and Write an XML File using PHP

How to read and write xml document with php’s DOMDocument. The DOM extension allows you to operate on XML documents through the DOM API with PHP 5. For better understanding, I have written comment for almost every line of code. XML Code: file name – employee.xml [xml] <?xml version="1.0"?> <employees> <employee id="1" name="Albert"><age>34</age><![CDATA[ Employee details …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/07/read-and-write-an-xml-file-using-php/

Guide to MySQL database Engine.

A MySQL database gives you a choice of database engines and an easy way to switch them. Default MySQL Engine would be enough for most of your application but in certain circumstances where the other available engines may be better suited to the task at hand. Choose your engine The number of database engines available …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/06/guide-to-mysql-database-engine/

Difference between $this and self?

Inside a class definition, $this refers to the current object, while self refers to the current class. It is necessary to refer to a class element using self, and refer to an object element using $this. self::STAT // refer to a constant like this self::$stat // static variable $this->stat // refer to an object variable …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/04/difference-between-this-and-self/

Double and Triple equals operator in PHP

Have you been given a piece of code to maintain that has single, double and triple equal operators in it? What’s the difference? Single Equals A single equal sign in PHP is an assignment operator. It assigns the value of the right side to the variable on the left side. For example: $name = “jon”; …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/04/double-and-triple-equals-operator-in-php/

Include a file and store contents to variable

This very handy feature of PHP which allows you to include a file but store the contents of the included file to a variable. This is particularly useful for PHP scripts and software which output content to a page by using variables. Many CMSs are built like this. The principal behind this solution is to …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/04/include-a-file-and-store-contents-to-variable/

Installing PEAR Mail for PHP On Ubuntu

It helps you how to make Ubuntu PHP localhost mail function work, using PHP to send mail from localhost is easy. First, you need to install some PEAR mail packages. In terminal, run the following command one by one: sudo apt-get install php-pear sudo pear install mail sudo pear install Net_SMTP sudo pear Auth_SASL sudo …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/01/installing-pear-mail-for-php-on-ubuntu/

How to Create a CAPTCHA with PHP

CAPTCHA is a simple test to determine if a user is a computer or a human. It is used to prevent spam abuse on the websites. So if you use CAPTCHA on your web site forms, this can help in stopping some bots and making life harder for other bots in accessing or using your …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/01/how-to-create-a-captcha-with-php/

Enable curl for PHP

We come across web applications which are written in PHP and require curl extension. PHP curl functions can used through use of libcurl. The libcurl was create by Daniel Sternberg. With the help of libcurl you can connect and communicate with webserver using different protocols. cURL stands for Client for URLs. It allows us to …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/01/enable-curl-for-php/