man5 Posted July 16, 2014 Share Posted July 16, 2014 (edited) $link = ?><a href="post?id=<?php echo $id; ?>&title=<?php echo $slug_title; ?>"><?php echo $title; ?></a><?php Basically what I am trying to do is get a url link of a current page that I'll be sending in an email. I have all the $_GET variables I need to duplicate the current url. For some reason it's giving me an error. Can you please fix what is shown above into something that'll work? Thanks. Edited July 16, 2014 by man5 Quote Link to comment https://forums.phpfreaks.com/topic/289926-quick-help-with-making-a-variable-a-link/ Share on other sites More sharing options...
DavidAM Posted July 16, 2014 Share Posted July 16, 2014 It would help us to help you if you would tell us what the error message says. I don't think that is valid code. You start a PHP assignment and drop out of PHP. You are also echoing values, they are going to go to the output, NOT the variable assignment. You should just concatenate the variables into a string; or, my personal preference: $link = sprintf('<a href="post?id=%s&title=%s">%s</a>', $id, $slug_title, $title); 1 Quote Link to comment https://forums.phpfreaks.com/topic/289926-quick-help-with-making-a-variable-a-link/#findComment-1485412 Share on other sites More sharing options...
PravinS Posted July 16, 2014 Share Posted July 16, 2014 You can use it like this also <?php $link = '<a href="post?id='.$id.'&title='.$slug_title.'">'.$title.'</a>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/289926-quick-help-with-making-a-variable-a-link/#findComment-1485426 Share on other sites More sharing options...
Solution man5 Posted July 17, 2014 Author Solution Share Posted July 17, 2014 Perfect! That's exactly what I needed. Thanks fellas. Quote Link to comment https://forums.phpfreaks.com/topic/289926-quick-help-with-making-a-variable-a-link/#findComment-1485519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.