PHP Tutorials

Wrap text

Table: my_quotes

quote_id quote auth_fn auth_mn auth_ln subject
1 I am beginning to suspect all elaborate and special systems of education. They seem to me to be built up on the supposition that every child is a kind of idiot who must be taught to think. Anne   Sullivan education
2 Creativity is a type of learning process where the teacher and pupil are located in the same individual. Arthur   Koestler education
3 Education is a better safeguard of liberty than a standing army. Edward   Everett education
4 Education is what remains after one has forgotten everything he learned in school. Albert   Einstein education

Wrapping words

In this tutorial you can learn how to wrap from content from the database.

wrap_text.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Text Wrap</title>
</head>

<body>

<?
include("my_connection.php");

$myQuery = mysql_query("SELECT * FROM my_quotes LIMIT 0, 10") or die (mysql_error());
while($myRow = mysql_fetch_object($myQuery)) {

$myOriginalText = $myRow -> quote;
$myWrappedText = wordwrap($myOriginalText, 25, "<br />");

echo "<p>" . $myWrappedText . "</p>";

}

?>

</div>
</body>
</html>

my_connection.php
<?php
mysql_connect("your-mySQL-server.yourdomain.com","your-user-name","your-password") or die ("your own error message");
mysql_select_db ("your-database-name") or die ("your own error message");
?>
PHP Tutorials
Other Tutorials