How to prepend a string in PHP

Topic: PHP / MySQL« Prev|Next »

Answer: Use the PHP Concatenation Operator

There's no specific function to prepend a string in PHP. But you can use the PHP concatenation operator (.) to prepened a string with another string.

  • <?php
  • $a = "Hello";
  • $b = "World!";
  • $b = $a . " " . $b;
  • echo $b; // Outputs: Hello World!
  • ?>

See the PHP operators tutorial to learn more about operators.


Related FAQ

Here are some more FAQ related to this topic:

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.