Solved

Limit URL length - PHP

Posted on 2013-12-10
5
253 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
Comment Utility
Try the built-in PHP function substr($thing,0,250);
0
 

Author Comment

by:_PJ_
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

772 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

13 Experts available now in Live!

Get 1:1 Help Now