Cutting up a string

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Fri Jul 08, 2005 8:50 pm    Post subject: Cutting up a string Reply with quote

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 View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Fri Jul 08, 2005 9:36 pm    Post subject: Re: Cutting up a string Reply with quote

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 View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Sat Jul 09, 2005 1:04 am    Post subject: Reply with quote

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 View user's profile Send private message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Sat Jul 09, 2005 10:26 am    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Sat Jul 09, 2005 5:54 pm    Post subject: Reply with quote

Thanks MonkeyNation, the wordwrap() worked a treat.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group