B
B
Blackman2011-10-23 10:51:32
PHP
Blackman, 2011-10-23 10:51:32

Shortening long links in PHP

Good day!

How to shorten long links in PHP?
What for? So that they do not climb out of the block, which is smaller than the link itself.

For example, if there is a link:
www.google.com.ua/#sclient=psy-ab&hl=uk&site=&source=hp&q=%D0%B1%D0%BB%D0%B0-%D0%B1%D0%BB%D0 %B0-%D0%B1%D0%BB%D0%B0&pbx=1&oq=&aq=&aqi=&aql=&gs_sm=&gs_upl=&bav=on.2 ,or.r_gc.r_pw.r_cp.,cf.osb&fp=d5d4317270f6af0c&biw=1920&bih =944&pf=p&pdl=500

How to make it look like:

<a href="полная ссылка">http://www.google.com.ua/#sclient=psy-ab&hl=uk&site=&source=hp...</a>

?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Elkaz, 2011-10-23
@Elkaz

php.net/substr

A
Andrew, 2011-10-23
@Morfi

It's probably more logical to use css
text-overflow: ellipsis

C
chmv, 2011-10-23
@chmv

if (strlen($value) > $maxlen) {
	$chars = floor($maxlen / 2);
	return substr($value, 0, $chars) . '...' . substr($value, -1 * $chars);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question