Solved

PHP Parse Error

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

820 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