Solved

PHP Parse Error

Posted on 2008-06-10
5
181 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
restriction of entering a a page 5 44
Difference between PHPClasse.php and SimplXLS.php 5 45
PHP substring 3 50
How do I init a PHP page jusing JQuery? 8 28
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…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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