• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

How to append two strings in PHP | Simple ways

How to append two strings in PHP

In this post we will discuss about append two strings in PHP. PHP (Hypertext Pre processor) is an interpreter and open source script language that is used on Linux Web Servers. It is mainly used for web development and can be embedded into HTML.It can also be used as a programming language. The best feature of PHP is it is very simple and easy to learn. Compared to other programming languages like C or Perl, PHP contains HTML with embedded codes.

How to append two strings in PHP

Requirements to run PHP

PHP is a server side scripting language where the PHP codes can be handled directly on the web server. To run PHP code, you must just to install the following in your machine.

  • Install a Web Server (e.g., Apache)
  • Install a PHP (Interpreter)
  • Install a MySQL Database (optional)

Note: If your server supports PHP, then create the .php files and place them on your web directory. You do not need to compile them. After discussing what is php lets go through the actual code to append two strings using php language. PHP is considered as the most used language on web for websites specially wordpress websites.

Basic PHP Syntax

A PHP script can be placed anywhere in the code. The PHP code is enclosed with a beginning as <?php and end as ?>  .

Example:

	<?php
	  //PHP Code
	?>

 

The file extension for PHP file is “.php”.

PHP Operators

The PHP operators are used to perform operations on variables and values. PHP supports more than 50 types of operators, starting from arithmetical operations to the logical comparison. Few operators that are generally used are as follows:

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Concatenation Operators

Let us discuss more on PHP concatenation operators.

PHP Concatenation Operators

There are two operators that are used for strings in the concatenation.

Operator Description
. Concatenation operator to combine two strings to create one ($txt1 . $txt2)
.= Concatenation assignment.

Appending two or more strings is string concatenation. You can easily concatenate the strings in PHP. To perform a string concatenation, use the concatenation operator “.” (dot). Echo is used to output the data to the screen. It can be used with parentheses or without parentheses i.e echo ( ) or echo.

Append two strings in php Code – 1

<?php
$str1  = 'This ‘;
$str2  = 'is a ‘;
$str3  = 'test string‘;
$full= $str1.$str2.$str3;
echo$full;
?>

The output for the above code looks like:

“This is a test string”

Further, use the operator “.=” to append a string to an existing code as follows:

Append two strings in php Code – 2

<!--?php $str = 'This is the base string'; 
$str .= ' and this is added; 
echo$str; ?-->

The output for the above code looks like:

“This is the base string and this is added”

Appending Strings and Variables

We can combine variables with strings, but cannot append with complex data types (i.e arrays or objects into strings).

Examples of concatenating integers looks like:

Code

<?php
$i = 90;
$str = $i.' is a number'; 
echo$str;
?>

The output for the above code looks like:

90 is a number

Examples of concatenating floats looks like:

Code
<?php
$percentage = 15.5 + 12 + 35.17;
echo 'Your final score: '.$percentage.' out of 100%.';
?>

The output for the above code looks like:

Your final score: 62.67 out of 100%.

Though PHP is focused on server side scripting, you can play more with PHP to make it interesting. Other areas where PHP is used are command line scripting and while writing desktop applications. PHP supports almost all the web servers and used in all operating systems. One of the significant features of PHP is it supports a wide range of databases. It also works as a module or as a CGI processor.

For more PHP projects and codes please visit.

Other Projects to Try:

  1. Factorial,Greatest Number,String Palindrome Shell code
  2. To Perform various String Operation in Java
  3. string operations such as Copy, Length, Reversing, Palindrome, Concatenation
  4. Operator Overloading on String Functions C++ Language
  5. PHP projects with Source Code

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy