Results 1 to 10 of 10

Thread: Replace html tags

  1. #1
    Join Date
    Jul 2008
    Posts
    81
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Default Replace html tags

    Hi is it possible to replace some html lines, that don't have any special id/name.

    example:

    PHP Code:
    <tr><td style="height: 10px;">nice <a href="http://www.google.com" target="_blank">link</a></td></tr
    to:

    PHP Code:
    <tr><td style="height: 10px; display:none;">nice <a href="http://www.google.com" target="_blank">link</a></td></tr
    using php str replace or any other way?

    thanks
    Last edited by lord22; 08-03-2008 at 09:20 AM.

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    You would definitely need a regular expression. I'm no expert, but here's a RegEx tutorial: http://www.regular-expressions.info/tutorial.html

    You would have to use preg_replace()
    - Mike

  3. #3
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    I'm no expert either, but if you found some special "class" or "ID" for a parent item, then you could do it with nested CSS... It's messy, but it would work.


    something like this...

    Code:
    <style type="text/css">
    .parent_item_class{
    margin:0px;
    }
    .parent_item_class table tr td td td tr td{
    display:none;
    }
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Well it's also possible with JavaScript I suppose. Not server-side, but oh well:

    Code:
    <script type="text/javascript">
    window.onload = function() {
      var td = document.getElementsByTagName("TD");
      for (var i = td["length"]-1;i > -1;--i) {
        if ((td[i]["id"])["length"] < 1) {
          td[i]["style"]["display"] = "none";
        };
      };
    };
    </script>
    - Mike

  5. #5
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    Or maybe something like htmlSQL.

  6. #6
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    Quote Originally Posted by mburt View Post
    Well it's also possible with JavaScript I suppose. Not server-side, but oh well:

    Code:
    <script type="text/javascript">
    window.onload = function() {
      var td = document.getElementsByTagName("TD");
      for (var i = td["length"]-1;i > -1;--i) {
        if ((td[i]["id"])["length"] < 1) {
          td[i]["style"]["display"] = "none";
        };
      };
    };
    </script>
    But wouldn't that set ALL <td> tags to "display:none;"?
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  7. #7
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    It will set the display to none if the TD didn't have an ID tag:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title></title>
    <script type="text/javascript">
    window.onload = function() {
      var td = document.getElementsByTagName("TD");
      for (var i = td["length"]-1;i > -1;--i) {
        if ((td[i]["id"])["length"] < 1) {
          td[i]["style"]["display"] = "none";
        };
      };
    };
    </script>
    </head>
    <body>
    <table>
    	<tr>
    		<td>test</td>
    		<td id="foo">asd</td>
    		<td id="foo1">asd</td>
    		<td id="foo2">asd</td>
    	</tr>
    </table>
    </body>
    </html>
    - Mike

  8. #8
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    ah ha! ok, understood.
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  9. #9
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    Quote Originally Posted by mburt View Post
    It will set the display to none if the TD didn't have an ID tag:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title></title>
    <script type="text/javascript">
    window.onload = function() {
      var td = document.getElementsByTagName("TD");
      for (var i = td["length"]-1;i > -1;--i) {
        if ((td[i]["id"])["length"] < 1) {
          td[i]["style"]["display"] = "none";
        };
      };
    };
    </script>
    </head>
    <body>
    <table>
    	<tr>
    		<td>test</td>
    		<td id="foo">asd</td>
    		<td id="foo1">asd</td>
    		<td id="foo2">asd</td>
    	</tr>
    </table>
    </body>
    </html>
    Ah, but what if the <td> was a "class='whatever'"?

    wouldn't you need to add something like:

    Code:
    if ((td[i]["class"])["length"] < 1)
    ???
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  10. #10
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    <script type="text/javascript">
    window.onload = function() {
      var td = document.getElementsByTagName("TD");
      for (var i = td["length"]-1;i > -1;--i) {
        if ((td[i]["id"])["length"] < 1 && td[i]["className"] == "whatever") {
          td[i]["style"]["display"] = "none";
        };
      };
    };
    </script>
    - Mike

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
  •