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

Posted on 2004-10-22
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
    LVL 49

    Accepted Solution

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


    LVL 49

    Expert Comment

    Um. My error. Should be:

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

    LVL 36

    Expert Comment

    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:

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

    $finishedstring="Test out";
    LVL 12

    Expert Comment


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

    count the number of "-"

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

    is this what you asking?
    LVL 9

    Expert Comment

    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

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

    aka Pern

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now