Re: cut off a string?



writes:

> Hey all,
> I have a small CMS tool that users can leave a max 200 characters message.

> everthing is fine but IF someone does something like this:

> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> 200 characters long

> my whole layout bearks appart even when i use style="width:300px" etc

> so is there a premade function in php that splits my words?

Use wordwrap http://uk.php.net/manual/en/function.wordwrap.php

Example 2 does what you want -

<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", 1);

echo "$newtext\n";
?>

This example would display:

A very
long
wooooooo
ooooord.

--

__o Alex Farran - Open source software specialist
_`\<,_ PHP | MySQL | E-Commerce | Content Management
(_)/ (_) site: www.alexfarran.com blog: alexfarran.blogspot.com
phone:01273 474065 mobile:07790 389330
.



Relevant Pages

  • Re: cut off a string?
    ... > Hey all, ... > I have a small CMS tool that users can leave a max 200 characters message. ... > everthing is fine but IF someone does something like this: ...
    (comp.lang.php)
  • Re: cut off a string?
    ... > Hey all, ... > I have a small CMS tool that users can leave a max 200 characters message. ... > everthing is fine but IF someone does something like this: ...
    (comp.lang.php)
  • cut off a string?
    ... Hey all, ... I have a small CMS tool that users can leave a max 200 characters message. ... everthing is fine but IF someone does something like this: ...
    (comp.lang.php)