Solved

PHP Parse Error

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
The viewer will learn how to dynamically set the form action using jQuery.
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 …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now