Solved

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

Posted on 2004-10-22
192 Views
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

thx
Johnny
aka Pern
0
Question by:Johnny
    6 Comments
     
    LVL 49

    Accepted Solution

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

    Regards

    -r-
    0
     
    LVL 49

    Expert Comment

    by:Roonaan
    Um. My error. Should be:

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

    -r-
    0
     
    LVL 36

    Expert Comment

    by:Zyloch
    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
     
    LVL 12

    Expert Comment

    by:minichicken
    Hi

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

    count the number of "-"

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

    is this what you asking?
     
    0
     
    LVL 9

    Expert Comment

    by:_GeG_
    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
     

    Author Comment

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

    Johnny
    aka Pern
    0

    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? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=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