Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add a fixed string character at the end of line 2

Status
Not open for further replies.

jollydonkey

Technical User
Sep 5, 2008
23
CA
Hello,

I'm stumped - I'm hoping someone can help me out.

I have a form text field in which a user can enter a title of sorts. The title can be any number of characters in length upto a maximum of 60 characters.

Now, at the end of the title, I'd like to use PHP to append a "|" character to the end of the title, fixed at character position number 72.

For example,
Code:
Study Title: THIS IS MY STUDY TITLE                                    |

I'm hoping someone can steer me in the right direction.

Thanks!

Cheers,
jd.
 
So if $input holds the name of my Study Title, the character "|" will output in the 72nd character column?

I tried that and the "|" is appended right after the last character in my Study Title.

I'm still confused. Ideas?

Cheers,
jd.
 
The problem is that HTML is white space agnostic. So any white spaces get reduced to a single one for display in a Webpage.
So even though there are in fact enough white space characters in your string, when displayed the white space gets reduced to one.

However if you check the string it is in fact 72 characters long.


If you look at your source you'll see that there is a bunch of space between your title and the | character.

You could of course add enough "&nbsp" characters to get it the way you want.

Code:
$input="This is a title";

$count=strlen($input);

for($i=0;$i<=(71-$count);$i++){
$input.="&nbsp";
}
$input.="|";

My question would be why exactly do you need 72 characters. Maybe there's a better way of accomplishing what you want.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi Vacunita,

By golly, you are absolutely right! I didn't clue in.

Basically, I need 72 characters because I want to format a user's form inputs in an attractive way. Headers will look something like this:

Code:
 --------------------
| TITLE:             |
 --------------------

Any tips? You've provided me some good insight already (I'm a novice).

Thanks!
 
Bad idea to use nothing but filling spaces to layout/position your page content. I suggest you pay a visit to

Code:
[URL unfurl="true"]http://www.w3schools.com/[/URL]

A very rich source for novice and experienced alike.

Good luck!



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
I'm not that much of a novice :) Output will actually be via an email form - so jaxtell's solution above hopefully will work out. I just didn't clue in the nuances of HTML during my preview testing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top