Replacing HTML tags

Discussion in 'PHP' started by makeit easy, Jun 28, 2010.

  1. #1
    How can I replace
    />
    with
    >

    For example;

     I need this: <img src="">  
    not <img src="" />
    HTML:
    XHTML needs " />" at the end of HTML codes.
    But I moved to HTML doc type from XHTML and the pages became not valid.

    I found this: http://php.net/manual/en/function.str-replace.php
    but couldn't write a code.
     
    makeit easy, Jun 28, 2010 IP
  2. frank100

    frank100 Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    str_replace("/>",">",$string);
    should work...but have not tested
     
    frank100, Jun 28, 2010 IP
  3. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Nothing to test
    This will work

    
    <?php
    $string= "<img src=\"\" />";
    $string= str_ireplace("/>",">",$string);
    ?>
    
    PHP:
     
    roopajyothi, Jun 29, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    You don't need str_Ireplace as theirs nothing to replace thats case insensitive, furthermore consider using preg_replace for reliability.
     
    danx10, Jun 29, 2010 IP
  5. makeit easy

    makeit easy Active Member

    Messages:
    2,067
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #5
    I tried preg_replace too but they don't work. They don't change "/>" and " />" as ">"
    I added your codes to several php files of WP.

    I also couldn't find a wp plugin for this.

    I removed the tick from the box in front of "WordPress should correct invalidly nested XHTML automatically" at wp-admin/options-writing.php
    but it is still adding " />" and validate the HTML codes as XHTML doc type.

    It was upgraded to the latest version, wp 3.0.
    I found this plugin: http://wordpress.org/extend/plugins/validation-helper/ but "THIS PLUGIN IS NO LONGER SUPPORTED!" I am starting to think it is impossible to have a WP with HTML doc type.
     
    makeit easy, Jun 29, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    Why would you not want XHTML but HTML?
     
    danx10, Jun 29, 2010 IP
  7. makeit easy

    makeit easy Active Member

    Messages:
    2,067
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #7
    I want to test HTML 4.01 Transitional as I can't validate the strict version.
    I recently noticed that all of my sites are with XHTML except the one which I purchased a while ago. It's a very simple custom design site with no database and feeds. It has very few content, less than 50 pages in total. But it always gets higher SERPs with a few very poor SEO. I strongly suspect from its HTML doc type. I changed the doc of my WP site but I can't validate it. This is an auto-post wp site with more than 10k pages indexed. If I can validate the pages, this will be a very good test and will show me the effect of doc type over SERPs.
     
    makeit easy, Jun 29, 2010 IP
  8. makeit easy

    makeit easy Active Member

    Messages:
    2,067
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #8
    I have just noticed that most of the biggest sites including yahoo, google, youtube, wikipedia, etc. use HTML doc types.
    You can check the other biggest sites: http://www.alexa.com/topsites

    There must be a good reason behind this. That's why I want to try HTML.
     
    makeit easy, Jun 29, 2010 IP