Solved

PHP Parse Error

Posted on 2008-06-10
5
183 Views
Last Modified: 2013-12-13
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
Comment
Question by:MariusGM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 21749731
print (substr($row_emptyJobs['comp_name'], 0, $limit)   << you are missing )
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21749733
if needs sourrounding ()

should be

if (strlen($row_emptyJobs['comp_name']) > $limit) {
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21749739
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
 

Author Comment

by:MariusGM
ID: 21749829
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
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 21749894
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question