Re: Modify data brought in via <?php include
Posted: Sun Jan 18, 2009 2:42 pm
Or post the URL you are trying to connect to. And when I said code, I mean the PHP you are using to fetch the contents of that URL. Including the URL. Please.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
As you can see below the html file if you look at it directly by typing the URL into browser you will get the the images/maps src link..Burrito wrote:if it's outputting something but not changing it, then file_get_contents() is NOT your problem. Post a small snippet it of what it returns in here that you'd like replaced and I'll take a look at it.
Code: Select all
<p><strong>Today Mon, 19 Jan 2009 is not a Day of Total Fire Ban.</strong>
</p>
<p><img src="images/maps/tfb_0.gif" width="250" height="185" border="0" alt="Total Fire Ban Districts" usemap="#Map"></p>
<map name="Map" id="Map">
<area shape="poly" coords="1,5" href="#" />
<area shape="poly" coords="2,121,1,4,19,8,35,10,45,30,56,26,63,28,71,44,78,52,93,66,94,88,107,105,85,117,68,105,44,116,34,110,16,116" href="images/maps/north_western_tfb_district.gif" target="_blank" alt="North Western District" title="Click to view a map of the North Western District"/>
<area shape="poly" coords="2,125,2,146,17,157,24,152,36,155,47,158,62,166,74,171,80,158,80,147,68,139,74,126,69,108,61,112,46,120,30,115,15,122" href="images/maps/south_western_tfb_district.gif" target="_blank" alt="South Western District" title="Click to view a map of the South Western District" />
<area shape="poly" coords="77,122,83,117,93,116,104,115,108,121,110,127,116,124,125,129,135,129,143,128,143,134,135,138,133,147,132,154,133,161,130,166,125,160,126,150,119,151,111,159,116,145,113,138,105,141,98,145,95,149,104,149,84,160,82,149,71,139" href="images/maps/central_tfb_district.gif" target="_blank" alt="Central District" title="Click to view a map of the Central District" />
<area shape="poly" coords="97,72,108,77,114,70,126,69,140,74,157,73,170,77,181,73,191,73,194,82,196,87,198,94,183,96,175,97,174,105,175,113,165,113,156,111,155,118,153,123,149,127,140,123,130,126,123,124,118,120,113,121,107,112,110,104,108,97,103,94,105,86,97,84" href="images/maps/north_eastern_tfb_district.gif" target="_blank" alt="North Eastern" title="Click to view a map of the North Eastern District" />
<area shape="poly" coords="138,171,134,160,136,148,140,136,151,130,159,115,171,118,180,116,178,102,189,98,198,100,206,104,232,117,247,126,243,128,235,135,215,135,195,138,181,147,171,158,161,166,155,169,149,166,147,171,153,181" href="images/maps/eastern_tfb_district.gif" target="_blank" alt="Eastern District" title="Click to view a map of the Eastern District" />
</map>
However i get the same result using both file_get_contents() and include()..Burrito wrote:now I'm confused: are you generating that html string with file_get_contents() as you said you were before or are you getting that using include() or from an iframe?
How would i manipulate it..Everah wrote:Use file_get_contents() and manipulate the string once you have it.
Code: Select all
<?php
$input = file_get_contents('http://www.somesite.com/page.htm');
$output = str_replace('images/maps', 'http://www.somesite.com/images/maps', $input);
echo $output
?>
Code: Select all
<p><strong>Today Mon, 19 Jan 2009 is not a Day of Total Fire Ban.</strong>
</p>
<p><img src="images/maps/tfb_0.gif" width="250" height="185" border="0" alt="Total Fire Ban Districts" usemap="#Map"></p>
<map name="Map" id="Map">
<area shape="poly" coords="1,5" href="#" />
<area shape="poly" coords="2,121,1,4,19,8,35,10,45,30,56,26,63,28,71,44,78,52,93,66,94,88,107,105,85,117,68,105,44,116,34,110,16,116" href="images/maps/north_western_tfb_district.gif" target="_blank" alt="North Western District" title="Click to view a map of the North Western District"/>
<area shape="poly" coords="2,125,2,146,17,157,24,152,36,155,47,158,62,166,74,171,80,158,80,147,68,139,74,126,69,108,61,112,46,120,30,115,15,122" href="images/maps/south_western_tfb_district.gif" target="_blank" alt="South Western District" title="Click to view a map of the South Western District" />
<area shape="poly" coords="77,122,83,117,93,116,104,115,108,121,110,127,116,124,125,129,135,129,143,128,143,134,135,138,133,147,132,154,133,161,130,166,125,160,126,150,119,151,111,159,116,145,113,138,105,141,98,145,95,149,104,149,84,160,82,149,71,139" href="images/maps/central_tfb_district.gif" target="_blank" alt="Central District" title="Click to view a map of the Central District" />
<area shape="poly" coords="97,72,108,77,114,70,126,69,140,74,157,73,170,77,181,73,191,73,194,82,196,87,198,94,183,96,175,97,174,105,175,113,165,113,156,111,155,118,153,123,149,127,140,123,130,126,123,124,118,120,113,121,107,112,110,104,108,97,103,94,105,86,97,84" href="images/maps/north_eastern_tfb_district.gif" target="_blank" alt="North Eastern" title="Click to view a map of the North Eastern District" />
<area shape="poly" coords="138,171,134,160,136,148,140,136,151,130,159,115,171,118,180,116,178,102,189,98,198,100,206,104,232,117,247,126,243,128,235,135,215,135,195,138,181,147,171,158,161,166,155,169,149,166,147,171,153,181" href="images/maps/eastern_tfb_district.gif" target="_blank" alt="Eastern District" title="Click to view a map of the Eastern District" />
</map>
Code: Select all
$input = "<img src=\"images/maps/someimage.jpg\">";
$output = str_replace('images/maps', 'http://www.somesite.com/images/maps', $input);
echo htmlentities($output);
After alot ofBurrito wrote:does exactly what it's supposed to for me....I"m guessing file_get_contents() isn't returning what you think it is for whatever reason. Try running it through htmlentities().Code: Select all
$input = "<img src=\"images/maps/someimage.jpg\">"; $output = str_replace('images/maps', 'http://www.somesite.com/images/maps', $input); echo htmlentities($output);
Code: Select all
<!-- START TFB STATUS -->
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td>
<p align="center"><font size="4" color="#000000"><b>TOTAL FIRE BAN STATUS</b></font>
<br />
<br />
<font size="2" color="#000000">
<b>Fire Restrictions NOW In Force
<br />
<img src="/images/tfbfr.gif" alt="Fire Restrictions" />
<br />
Our Fire Brigade is located within the
<br />
Central Total Fire Ban District
</b></font></p>
</td>
<td style="width: 5px">
</td>
<td>
<font size="1">
<!-- TFB INPUT -->
<?php
$input = file_get_contents('http://www.somesite.com/tfb.htm');
$output = str_replace('images/maps', 'http://www.somesite.com/images/maps', $input);
echo htmlentities($output);
?>
<!-- END TFB INPUT -->
</font>
</td>
</tr>
</tbody>
</table>
<!-- END TFB STATUS -->