Jump to content

Simple Syntax Problems


Bopo

Recommended Posts

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

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

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 />';
  
}

?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.