How to replace <font> tags with <span> tags
Posted: Mon Jan 26, 2009 12:15 pm
Hi there,
I'm quite new to php and am trying to replace font tags with span tags or to delete font tags all together as they are not xhtml valid.
I'm using file_get_contents to display current weather from superpages.com. it comes in fine but the code it produces uses font tags and other old tags such as <br>, <u>,<b>. I'd like to make the output xhtml valid but just don't know how to get rid of those old tags I've tried str_replace and preg_replace without great success. The following code did convert two <font></font> lines to <span></span> but other font tags that were not at the start of a line did not change:
Here is the output that the above produced - you can see all of the font tags still there:
I would also like to change the <td> bgcolor to a style also.
Any guidance will be greatly appreciated.
Thanks,
Trish
I'm quite new to php and am trying to replace font tags with span tags or to delete font tags all together as they are not xhtml valid.
I'm using file_get_contents to display current weather from superpages.com. it comes in fine but the code it produces uses font tags and other old tags such as <br>, <u>,<b>. I'd like to make the output xhtml valid but just don't know how to get rid of those old tags I've tried str_replace and preg_replace without great success. The following code did convert two <font></font> lines to <span></span> but other font tags that were not at the start of a line did not change:
Code: Select all
<?php
$content = file_get_contents("http://www.superpages.com/cities/console.pl?T=Augusta&S=ME&Z=MEZ021&W=n120x120");
if ($content !== false) {
// do something with the content
$content = preg_replace('/<font(.*?)>(.*?)<\/font>/i', '<span>$2</span>', $content);
echo $content;
}else {
echo "error processing page"; // an error happened
}
?>
Code: Select all
<DIV style="display:none">
<!-- SiteCatalyst code version: H.9.
Copyright 1997-2007 Omniture, Inc. More info available at
http://www.omniture.com -->
<script language="JavaScript" src="//www.superpages.com/inc/s_code.js"></script>
<script language="JavaScript">
/* You may give each page an identifying name, channel, and hierarchy on the next lines. */
s.channel="Weather Consoles"
s.hier1="City Pages,Weather Pages,Weather Consoles"
<!-- End SiteCatalyst code version: H.9. -->
<!-- SiteCatalyst code version: H.9.
s.pageName=document.title;
var s_code=s.t();if(s_code)document.write(s_code);
</script>
</DIV>
<table width="123" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="http://img.superpages.com/images-yp/decor/images/spacer.gif" width=3></td>
<td colspan="2" valign="middle"><font face="Arial, Helvetica, sans-serif" color="#333333" size="1">
<span>Today: 1/26/09</span><br><img height=40 alt="Very cold" src="http://img.superpages.com/cities/weathericons/verycold.gif" width=40 align="right"><font color="#FF0033" face="Verdana, Arial, Helvetica, sans-serif">High
15°<br>
<span>Low 0°</span><br>
<span>Very cold</span></font></font></td>
</tr>
<tr>
<td colspan="4" height="20" align="center" bgcolor="#000066"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><a href="divination2.cgi?Z=MEZ021&T=Augusta&S=ME" target="_top"><font color="#FFFFFF"><u>Seven
Day Forecast</u></font></a></font></td>
</tr>
</table>
Any guidance will be greatly appreciated.
Thanks,
Trish