• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

PHP Parse Error

Hello Experts,

I'm trying to limit the characters returned for a column in a web app I'm creating. I'm using a little snippet I picked up in another forum and having a nightmare trying to implement it.

I keep getting a Parse error: syntax error, unexpected T_STRING, expecting '('

I have tried to debug this one myself but I'm not all to confident in PHP and at a bit of a loss. I'm sure one of you smart cookies will crack this in a few minutes no doubt...

Thanks.
<?php 
			$limit = 20; // Company Name Char limit
			if strlen($row_emptyJobs['comp_name']) > $limit {
			print (substr($row_emptyJobs['comp_name'], 0, $limit) . " ... ";
			}
			else {
			print $row_emptyJobs['comp_name'];
			} 
		  ?>

Open in new window

0
MariusGM
Asked:
MariusGM
  • 3
1 Solution
 
gamebitsCommented:
print (substr($row_emptyJobs['comp_name'], 0, $limit)   << you are missing )
0
 
hernst42Commented:
if needs sourrounding ()

should be

if (strlen($row_emptyJobs['comp_name']) > $limit) {
0
 
hernst42Commented:
You can also ommit the opening ( in the print
just

print substr($row_emptyJobs['comp_name'], 0, $limit) . " ... ";

Thats common practive and typical also used i the php manual that way.
0
 
MariusGMAuthor Commented:
Thanks for the rapid response ...

None of the above seems to have done the job I'm afraid.

The Parse Error is occurring in line 3 of the above code, if thats any help ...
0
 
hernst42Commented:
Try this code which works:
<?php
$limit = 20; // Company Name Char limit
if (strlen($row_emptyJobs['comp_name']) > $limit) {
    print substr($row_emptyJobs['comp_name'], 0, $limit) . " ... ";
}
else {
    print $row_emptyJobs['comp_name'];
}

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now