View Full Version : Replace html tags
lord22
08-03-2008, 07:44 AM
Hi is it possible to replace some html lines, that don't have any special id/name.
example:
<tr><td style="height: 10px;">nice <a href="http://www.google.com" target="_blank">link</a></td></tr>
to:
<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
mburt
08-03-2008, 09:44 PM
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()
TheJoshMan
08-03-2008, 09:48 PM
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...
<style type="text/css">
.parent_item_class{
margin:0px;
}
.parent_item_class table tr td td td tr td{
display:none;
}
mburt
08-03-2008, 09:52 PM
Well it's also possible with JavaScript I suppose. Not server-side, but oh well:
<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>
techietim
08-03-2008, 09:53 PM
Or maybe something like htmlSQL (http://www.jonasjohn.de/lab/htmlsql.htm).
TheJoshMan
08-03-2008, 09:55 PM
Well it's also possible with JavaScript I suppose. Not server-side, but oh well:
<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;"?
mburt
08-03-2008, 09:57 PM
It will set the display to none if the TD didn't have an ID tag:
<!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>
TheJoshMan
08-03-2008, 10:02 PM
ah ha! ok, understood.
TheJoshMan
08-03-2008, 10:03 PM
It will set the display to none if the TD didn't have an ID tag:
<!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:
if ((td[i]["class"])["length"] < 1)
???
mburt
08-03-2008, 10:11 PM
<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>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.