Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I concatenate a string in PHP? [closed]

Tags:

php

I want to echo a PHP function with some string literal HTML.

This is how I thought it was done:

echo '<a href="' + $prevpost->url()  + '" class="postnav left nextpost"></a>';

...but that returns nothing. I've tried small variations on where the quotes are etc. but I'm worried I'm barking up the wrong tree and I can't really find what I need from searching.

Note: echo $prevpost->url(); does return the URL I am trying to link to, before anybody asks if that works.

like image 431
sanjaypoyzer Avatar asked Feb 13 '26 12:02

sanjaypoyzer


2 Answers

The concatenation operator in PHP is . and not +

like image 195
Maxim Krizhanovsky Avatar answered Feb 15 '26 01:02

Maxim Krizhanovsky


Change it to below, in php . (dot) is used as a concatenation operation in php,

echo '<a href="' . $prevpost->url()  . '" class="postnav left nextpost"></a>';
like image 25
Rikesh Avatar answered Feb 15 '26 01:02

Rikesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!