View previous topic :: View next topic |
Author |
Message |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Fri Jul 08, 2005 8:50 pm Post subject: Cutting up a string |
|
|
I have recently aquired CMX's directory listing script and I am having some tweeking problems.
His original code only displays a certain amount of characters that you can easily change. Now I want to dislpay more but when it comes to limiting how much goes onto one line, it becomes a problem.
The code that does this is:
Code: | if (strlen($name) > 19) {
$name1 = substr($name,'0','15');
$name2 = substr($name,'15','30');
$name = "$name1<br>$name2";
} |
but when it comes to the second line, it ignores $name2 = substr($name,'15','30'); and just puts the rest of the characters in after that on the second line, without limiting it to 15 characters. The first line one is great and works fine, the second however does not.
I want this script to look more like windows explorer etc so displaying more of the filename can help.
Any help is appriciated. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Fri Jul 08, 2005 9:36 pm Post subject: Re: Cutting up a string |
|
|
The Inquisitor wrote: | I have recently aquired CMX's directory listing script and I am having some tweeking problems.
His original code only displays a certain amount of characters that you can easily change. Now I want to dislpay more but when it comes to limiting how much goes onto one line, it becomes a problem.
The code that does this is:
Code: | if (strlen($name) > 19) {
$name1 = substr($name,'0','15');
$name2 = substr($name,'15','30');
$name = "$name1<br>$name2";
} |
but when it comes to the second line, it ignores $name2 = substr($name,'15','30'); and just puts the rest of the characters in after that on the second line, without limiting it to 15 characters. The first line one is great and works fine, the second however does not.
I want this script to look more like windows explorer etc so displaying more of the filename can help.
Any help is appriciated. |
Wouldnt that be display 30 characters starting from position 15? That may be why.
Personally I think youd be better off using wordwrap() => http://uk.php.net/manual/en/function.wordwrap.php
Try that. _________________
 |
|
Back to top |
 |
 |
Anonymoose -
Joined: 09 Sep 2003 Posts: 2192
|
Posted: Sat Jul 09, 2005 1:04 am Post subject: |
|
|
http://uk.php.net/substr
As monkeynation said, the second number is for the length of the string to extract, not the end character. |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Sat Jul 09, 2005 10:26 am Post subject: |
|
|
Anonymoose wrote: | http://uk.php.net/substr
As monkeynation said, the second number is for the length of the string to extract, not the end character. |
Ah, right. I will go and try this. Thanks guys, owe you one. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Sat Jul 09, 2005 5:54 pm Post subject: |
|
|
Thanks MonkeyNation, the wordwrap() worked a treat. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
|