[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


id like to know if: i can tell how meny - are in a string like echo "#------------------------------------------------#<BR>";

Posted on 2004-10-22
Medium Priority
Last Modified: 2008-03-06
id like to eb able to adjust the strings - in
echo "#------------------------------------------------#<BR>";
so i can expand it at will with out typeing in all those -

is this posible

if it is a second question how would i find the lenth of
$UN to populate the amount of - id need adding 4 to each side (8 total) to make it look correct the size of the area

aka Pern
Question by:Johnny
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 49

Accepted Solution

Roonaan earned 2000 total points
ID: 12384322
echo '#'.str_repeat('-', strlen($UN)+4).'#<br/>';


LVL 49

Expert Comment

ID: 12384327
Um. My error. Should be:

echo '#'.str_repeat('-', strlen($UN)+8).'#<br/>';

LVL 36

Expert Comment

ID: 12384348
Well, first, I would recommend using a monotype font, something that yo would see in a textarea or Notepad for instance, or something in <pre> tags, otherwise, because each letter takes up a different space, it's quite difficult to make it look exactly right.

I would recommend using str_pad: http://us2.php.net/manual/en/function.str-pad.php

For instance, if you want a variable $finalstring to be 30 characters long between the # signs, then you can have this:

$finishedstring="Test out";
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 12

Expert Comment

ID: 12384410

length of string:
strlen("123456"); //returns 6

count the number of "-"

substr_count("#----#", "-"); // returns 4

is this what you asking?

Expert Comment

ID: 12384475
for your second question, use str_pad
if you want to have total lenght 30, use it like this:

echo str_pad('textextext', 30, "-", STR_PAD_BOTH);

Author Comment

ID: 12385084
thx for all the answers
but first is what i wanted perfect thx

aka Pern

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question