SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Converting HTML Tags

    Does anyone have a function to convert uppercase HTML tags to lowercase HTML tags?
    <///////~

    www.sohh.com

  2. #2
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This is definately possible using reg ex and a function - I've had a code snippet. I'll see if I can dig it out for you.
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  3. #3
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hmmm, something like this?

    PHP Code:
    preg_replace("/(<\/?)(\w+)([^>]*>)/e","'\\1'.strtolower('\\2').'\\3'",$html_body); 
    Edit:

    Oooops, if you've looked in the last couple of mins the codes been corrected - had it the wrong way round for ya!
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  4. #4
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just as a question, what would it do to attributes?

    Like if I had:

    <P CLASS="style">text</P>

    Would it convert it like:

    <p class="style">text</p>

    or:

    <p CLASS="style">text</p>
    <///////~

    www.sohh.com

  5. #5
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hmmm I don't have the means to test it at present, it should all return lower case, so the CLASS would become class - which is valid xhtml anyway (I presume what you're looking to do?).
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  6. #6
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Bugger!

    Had a chance to test it, used the following code:

    PHP Code:
    <?php

    $html_body 
    '<DIV ALIGN="CENTER">Hey You</DIV>';
    $new_htmlpreg_replace ("/(<\/?)(\w+)([^>]*>)/e",
                  
    "'\\1'.strtolower('\\2').'\\3'",
                  
    $html_body);

    echo 
    "$new_html";

    ?>
    and unfortunately the result was that the attributes remained upper case

    (
    Code:
    <div ALIGN="CENTER">Hey You</div>
    )

    I think we needs a regexpert to have a looksee.....
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS


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
  •