Is there a way to make an echo word wrap after so many characters?
I know
echo substr($string_to_be_echoed, 0, $number_of_chars);
restricts it, but i neec to use wordwrap instead....
[RESOLVED] Word wrap?
Guess this code works!!!
<?php
/**
Example usage:
// Your text
$text = "This is a sentence which contains some words.";
// Or from a database result
$text = $row['text'];
// Then put it into the function
$text = word_wrap($text);
// Output the result
echo $text;
/
function word_wrap($text) {
// Define the characters to display per row
$chars = "10";
$text = wordwrap($text, $chars, "<br />", 1);
return $text;
}
?>
I used the example on php.net, the code needed to me mdofyed a bit, i just didnt know that the function existed you can see a demo of it on my site( Programmer2.net ), the post comment thing uses it.
http://programmer2.net/demos/mp.php
Please dont post a long message that is all like 1 letter becouse if its junk, i will delete it....
yes bogu was very kind to post that one function. i don't know why i thought php wouldn't be able to to something simple like this. glad itworked for you too.