Solved

Limit URL length - PHP

Posted on 2013-12-10
5
255 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 108

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 108

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
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.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
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…

914 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

19 Experts available now in Live!

Get 1:1 Help Now