?
Solved

PHP Parse Error

Posted on 2008-06-10
5
Medium Priority
?
187 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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

800 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