Solved

Limit URL length - PHP

Posted on 2013-12-10
5
265 Views
Last Modified: 2014-10-22
Hello experts,

I need to setup the length of the URL created in the result set from my search engine. It needs to be up to 250 characters.

I retrieve the unique number of each study from id and its name from name

The name parameter is the one that should be limited because contains the study title.

  printf("<td><a href='http://mywebsite.com/%s,&radio=$radio,%s' target=\"_blank\">%s</a></td>",$row['id'], str_replace( $simbolos_reemplazar, "_", $row['name']), $row['name']);

Open in new window


Thanks in advance for the help
0
Comment
Question by:_PJ_
  • 2
5 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39708229
Try the built-in PHP function substr($thing,0,250);
0
 

Author Comment

by:_PJ_
ID: 39708251
Thanks Ray, I will try. It's ok my syntax?

printf("<td><a href='http://mywebsite.com/%s,&radio=$radio,%s' target=\"_blank\">%s</a></td>",$row['id'], str_replace( $simbolos_reemplazar, "_", $row['name']), $row['name']), substr($row[name],0,250);

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39708335
I don't know.  I am pretty sure you have unbalanced parentheses that will cause a parse error, but I can't really test it since I don't have your test data set.  I usually recommend that programmers avoid compound statements (AntiPractice #9) because it may be difficult to look at your code and know whether it will work or not.  Try breaking the code up into units that are susceptible of being examined one-at-a-time and you'll probably spend less time debugging!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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…
The viewer will learn how to dynamically set the form action using jQuery.

809 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