• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

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

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

thx
Johnny
aka Pern
0
Johnny
Asked:
Johnny
1 Solution
 
RoonaanCommented:
echo '#'.str_repeat('-', strlen($UN)+4).'#<br/>';

Regards

-r-
0
 
RoonaanCommented:
Um. My error. Should be:

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

-r-
0
 
ZylochCommented:
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";
$finishedstring=str_pad($finishedstring,30,"-",STR_PAD_BOTH);
$finishedstring="#".$finishedstring."#<br>";
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
minichickenCommented:
Hi

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

count the number of "-"

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

is this what you asking?
 
0
 
_GeG_Commented:
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);
0
 
JohnnyAuthor Commented:
thx for all the answers
but first is what i wanted perfect thx

Johnny
aka Pern
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now