Jump to content

Help indenting text in a DIV


coleby58

Recommended Posts

Hello there I'm sorry if this has already been solved somewhere I have looked for a while. I have a website where a user submits information in a form on a page then on submit the next page displays there info. What I need is when there info reaches a certain length in the DIV on the display page I need it to go drop to the next line and indent 5 spaces. All my pages refer to my css page so it would be nice if I could put one code in that page instead of on 100 pages.

 

here is an example of how I have the display page set up:

 

<html>

 

 

<head>

<title>Example</title>

 

<link rel="stylesheet" type="text/css"

href="example.css"/>

 

 

<script type="text/javascript" src="example.js"></script>

 

</head>

 

 

<body>

 

<center>

<div id="logo">

<a href="index.php">

<img border="0" src="example.JPG">

</a>

</div></center>

 

 

 

<div id="example">

<?php

$info = $_POST['info'];

if ($info=="")

echo "";

else

echo "$info";

?>

 

 

 

 

 

 

</div>

</body>

</html>

 

----------------------------------------------------------

 

As you can see there info is displayed with php. I'm still a begginer so I'm sorry if css is not the solution to my problem.

Link to comment
Share on other sites



<?php

  $info = $_POST['info'];  // grabs the data from the form

  $length=strlen($info);   // checks the length of the data string

  if ($length < 30) {       // decides WTH to do next
    $info = $info;           // leaves it as is, it's shorter than 30
  }
  else {
    $info = substr("$info",0,30) . "...";  // splits it into two lines (starts at character 0 and goes thirty spaces, then cuts it.)
    $info2 = substr("$info",31,30);      // you could add a third line by using ("$info",62,30) or whatever
  }

  echo "$info<br />                         // say it, don't spray it
       $info2";  // adds 5 spaces then prints characters 31 onward.
?>

 

Now, you could put all of this in a file called displayinfo.php and then

include it on any page you need it on with <?php include ('displayinfo.php') ?>

 

This should work, I didn't test it and I am tired but it's php 101.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.