SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Indent function

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Indent function

    I have a function to clean up my html when using templates.

    PHP Code:
    function indent($text,$n){
        if(
    is_string($text) && is_int($n)){
            
    $indent "";
            
    $i 0;
            while(
    $i $n){
                
    $i++;
                
    $indent.= "\t";
            }
            return 
    str_replace("\n""\n".$indentstr_replace(array("\r\n","\r"), "\n"$text));
        }

    Works perfect except when i have a textarea that has a load of line breaks in it and it adds 8 or so tabs in after each line break.
    I'm really bad with this kinda of thing, is there any way someone could help me with a regex to stop it doing that to anything between "[no-indent]" and "[/no-indent]" ?

    Thanks !

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Use Tidy instead to format HTML
    http://us3.php.net/manual/en/book.tidy.php
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    May 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    go get regex buddy and try it for yourself


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •