base href problem

I am trying to pull content from a national weather service page into my own site. This is the code that I’m using…

[php]<?php
$fname = “http://forecast.weather.gov/MapClick.php?CityName=Little+Rock&state=AR&site=LZK&textField1=34.7224&textField2=-92.3541&e=1”;
$content = file_get_contents($fname);
echo $content;
?>
[/php]

The problem is that image links from the imported page are all relative causing the browser to look for them on my server. adding the snippet
[php]echo “<base href=“http://forecast.weather.gov” />”;[/php]
works in firefox but not in IE since it is supposed to located in the of the page. However putting it in the breaks all other links on the page.

Is there any way to set a base href just for the code being pulled in by php?

Hi,

place base url before your code it will work:

[php] echo “<base href=“http://forecast.weather.gov” />”;
$fname = “http://forecast.weather.gov/MapClick.php?CityName=Little+Rock&state=AR&site=LZK&textField1=34.7224&textField2=-92.3541&e=1”;
$content = file_get_contents($fname);
echo $content;
[/php]

Or try this

[php] echo “<base href=“http://forecast.weather.gov” />”;
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, ‘http://forecast.weather.gov/MapClick.php?CityName=Little+Rock&state=AR&site=LZK&textField1=34.7224&textField2=-92.3541&e=1’);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
echo $result;
[/php]

Thank you however, neither one of those examples works. IE seems to only recognize the if it is located within the . Anywhere else, and it is ignored. Plus the second example threw an error.

Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\neaweatherwatcher.com\test.php on line 108

I am completely new to PHP and any help would be appreciated :smiley:

how about a way to take this

<img src="/images/wtf/image.jpg>

automatically prepend all

/images/wtf/image.jpg>

with

http://forecast.weather.gov

thereby creating

<img src="http://forecast.weather.gov/images/wtf/image.jpg>

Like I said, I am new to PHP and don’t even know if it is capable of parsing like this.

Okay, I finally got this fixed and thought I would share…

[php]

<?php //echo ""; $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, 'http://forecast.weather.gov/MapClick.php?CityName=Little+Rock&state=AR&site=LZK&textField1=34.7224&textField2=-92.3541&e=1'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($curl); $output = str_replace('/images/wtf/','http://forecast.weather.gov/images/wtf/',$result); echo $output; ?>

[/php]

The commented line is there only because, without it, the page navigation appears broken in DW Live View even though it displays properly in an actual browser. Go figure… BTW, the curl error was simply because I had not enabled it within XAMPP. This is a learning experience for me :smiley:

Glad that you got it through! :slight_smile: One tends to forget minor things! But that’s what helps you learn! Cheers!

Sponsor our Newsletter | Privacy Policy | Terms of Service