Bopo Posted March 27, 2009 Share Posted March 27, 2009 Hi This is quite a simple one, although it causing me problem as I can't get it correct. basically I want to ouput html tags around certain variables within my php script, however I always get a syntax error: <?php print '<a href="viewpost.php?postid=' . $row['id'] . '">' . $row['title'] . '</a>'; //h2 tags around the 'title' echo $row['author'].'<br />'; $trimpost = substr($row['post'],0,50); echo $trimpost . '...'; // <p> tags here print '<a href="viewpost.php?postid=' . $row['id'] . '">' . $moreinfo . '</a>'; ?> I know </a> is being output as a tag, but that's the only one I can get to work. Help appreciated. Link to comment https://forums.phpfreaks.com/topic/151392-simple-syntax-problems/ Share on other sites More sharing options...
steelaz Posted March 27, 2009 Share Posted March 27, 2009 Whats is the syntax error you're getting? It looks valid to me. Link to comment https://forums.phpfreaks.com/topic/151392-simple-syntax-problems/#findComment-795158 Share on other sites More sharing options...
mrfitz Posted March 27, 2009 Share Posted March 27, 2009 Hi This is quite a simple one, although it causing me problem as I can't get it correct. basically I want to ouput html tags around certain variables within my php script, however I always get a syntax error: <?php print '<a href="viewpost.php?postid=' . $row['id'] . '">' . $row['title'] . '</a>'; //h2 tags around the 'title' echo $row['author'].'<br />'; $trimpost = substr($row['post'],0,50); echo $trimpost . '...'; // <p> tags here print '<a href="viewpost.php?postid=' . $row['id'] . '">' . $moreinfo . '</a>'; ?> I know </a> is being output as a tag, but that's the only one I can get to work. Help appreciated. Hi, Your quotes are reversed... print '<a href="viewpost.php?postid=' . $row['id'] . '">' . $row['title'] . '</a>'; //h2 tags around the 'title' Reverse the ' for " and " for ' try that Mrfitz Link to comment https://forums.phpfreaks.com/topic/151392-simple-syntax-problems/#findComment-795168 Share on other sites More sharing options...
kenrbnsn Posted March 27, 2009 Share Posted March 27, 2009 The quotes are fine. The OP needs to post the error message. Ken Link to comment https://forums.phpfreaks.com/topic/151392-simple-syntax-problems/#findComment-795173 Share on other sites More sharing options...
Bopo Posted March 27, 2009 Author Share Posted March 27, 2009 Hi A little confusion, I was asking how I could do it, but I'll post some examples of what I'm trying to do, I've highlighted the lines and what html tags are causing the problem: Parse error: syntax error, unexpected T_VARIABLE <?php print '<a href="viewpost.php?postid=' . $row['id'] . '">' . '<h2>'$row['title']'</h2>' . '</a>'; // error due to h2 tags echo $row['author'].'<br />'; $trimpost = substr($row['post'],0,50); echo $trimpost . '...'; // error due to <p> tags print '<a href="viewpost.php?postid=' . $row['id'] . '">' . $moreinfo . '</a>'; // echo $row['post'].'<br />'; } ?> Link to comment https://forums.phpfreaks.com/topic/151392-simple-syntax-problems/#findComment-795186 Share on other sites More sharing options...
kenrbnsn Posted March 27, 2009 Share Posted March 27, 2009 On the first line, you forgot to use the concatenation operator between strings: <?php print '<a href="viewpost.php?postid=' . $row['id'] . '"><h2>' . $row['title'] . '</h2></a>'; ?> I don't see at "<p>" tags on the next line referenced. Ken Link to comment https://forums.phpfreaks.com/topic/151392-simple-syntax-problems/#findComment-795192 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.