Search code examples
phphtmlhref

Inserting html href link via echo mid sentence in php


I'm new to php so this may be a tedious question but I'm trying to insert an href link in my php code. I saw how to do this but I'm unsure how to use echo such that I can have text before and after it. I tried using the concatenating symbol (.) but am getting compiling errors. I would like the link to feature after some text. There will also be text after this link. This is what I have currently:

Session::flash('demo', "You're using a demo account - the changes that you make will not be stored. Learn more ".echo" <a href=$learnMore> here </a>");

It feels very wrong but I'm not sure how to solve it as it's my first time writing in the language. Any advice? Thank you so much :)


Solution

  • Not sure which frame work you are using but im pretty sure it should be more like:

    Session::flash('demo', "You're using a demo account - the changes that you make will not be stored. Learn more <a href='".$learnMore."'> here </a>");
    

    You are passing your string into a method called flash so there is no need to use the echo method to do anything. Instead just concat your variable into the string like above