简体   繁体   中英

PHP - How to add a specific character at the end of a string?

I am looking for hours how can i add an specific character at the end of a string.

Here is my code:

$string = "I have a";
$AddToEnd = "]";

I want to make AddToEnd to appear after the last character in $string .

How it is possible, thanks in advance!

See PHP's String Operators to see how to concatenate strings:

$finalString = $string . $AddToEnd;
// OR
$string .= $AddToEnd

You can also use a function like implode() :

$finalString = implode(array($string, $AddToEnd));

What you're looking for is called concatenation.

In PHP you have ms to do that :

$concat = $string . $AddToEnd;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM