cutting strings

This is a discussion on "cutting strings" within the PHP Forum section. This forum, and the thread "cutting strings are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 25th, 2007, 01:17
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
cutting strings

I would like to have a string be cut off if it is over a certain amount of characters and add ".." to the end of the string.
I think what I need is similiar to wordwrap but instead of starting a new line it just cuts the rest off.
sorry if that isn't clear enough.
cheers
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 25th, 2007, 01:21
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: cutting strings

sorry!
got it
substr()
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 26th, 2007, 01:22
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: cutting strings

Help needed again....
is there anyway to do this without breaking html tags?
and close any if they are left open?
google was not my friend today
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Aug 29th, 2007, 10:01
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: cutting strings

Alex ... Google wasn't being your friend because there is no easy way . It's easy enough to tell whether you're within a particular tag or not, but to tell whether you're between an open and a close when you chop something is trickier, especially if you're not using well-formed HTML.

I can across a need to truncate a piece of HTML that I had gathered as a result of a search, and be able to display it robustly. Similar to your requirement, I think? I took the approach of replacing all tags with " ... " and then using a regular expression rather than substr to ensure that the remaining snippet was a few characters shorter than my maximum if necessary, but always broken at a white space. See http://www.wellho.net/net/search.php4?search=friend for an example of what you can achieve through this approach.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Aug 29th, 2007, 16:39
Reputable Member
Join Date: Jan 2004
Location: California
Age: 19
Posts: 232
Thanks: 0
Thanked 2 Times in 2 Posts
Re: cutting strings

not sure what exactly your trying to do, but play around with this:
PHP: Select all

if ($string != "<html>") {
$newstring substr_replace($string,"",-4);
echo 
$newstring."..";

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 29th, 2007, 17:12
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: cutting strings

I think I might just strip all tags :/
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
cut, strings

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash is cutting off bits of my text...any ideas? Darkflame Flash & Multimedia Forum 2 Mar 19th, 2007 14:16
Scrollpane Cutting Off Content tox0tes Flash & Multimedia Forum 4 Jan 26th, 2007 19:50
Javascript Strings Help Sabin_33 JavaScript Forum 2 Dec 21st, 2006 09:54
Confused with strings... ktsirig Other Programming Languages 1 Jan 11th, 2006 18:02
Quotes in strings jakyra Classic ASP 5 Sep 9th, 2003 15:10


All times are GMT. The time now is 10:32.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42