man5 Posted July 16, 2014 Share Posted July 16, 2014 $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. 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); 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>'; ?> 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...
man5 Posted July 17, 2014 Author Share Posted July 17, 2014 Perfect! That's exactly what I needed. Thanks fellas. 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
Archived
This topic is now archived and is closed to further replies.