UBB.Dev
Posted By: smilesforu php relative output problem - 12/14/2003 7:02 AM
I have a news program that outputs the link to news coming from the state on new regulations. The link that is generated shows up as one on my site which is wrong. I need it to insert the proper url... example

proper link should look like this
http://www.wa.gov/wdfw/fish/regs/regchng/dec0903a.htm

but returns a link like this in my pal box
http://www.steelheader.net/ubbthreads/regchng/nov1903c.htm

I do a include from the txt file... should be a easy fix but its beyond me.

Code
 <?<br /><br />$filename ="wdfw_data.txt";<br />$handle= fopen($filename,'w');<br />$url="http://www.wa.gov/wdfw/fish/regs/fishregs.htm";<br />$result = shell_exec("wget -q -O - $url");<br /><br />$contents = Implode("", File($url));<br />preg_match_all("|<a\b([^>]+)>(.*?)</a>|i", $contents, $arrayoflinks);<br /><br />$x=1;<br />$pattern = "/\.\/regchng/i";<br />$replacement = "http://www.wa.gov/wdfw/fish/regs/regchng";<br /><br />while(List(,$link) = Each($arrayoflinks[0])){<br />	if (preg_match ("/regchng/i", "$link")) {<br />		if($x<11){<br />			$link = preg_replace($pattern, $replacement, $link);<br />			$resulting_data .= "$link<br>";<br />		}<br />		$x++;<br />	}<br />}<br /><br /><br /><br />fputs($handle, $resulting_data);<br /><br />exit;<br />?><br /><br /> 
Posted By: push Re: php relative output problem - 01/10/2004 10:53 PM
Not sure what you are trying to do - do you have a link to your news program? Or got anything further background information.

One thing that you should definitely add is an fclose($handle); after your fputs - just good practise.
Posted By: push Re: php relative output problem - 01/10/2004 11:07 PM
I think I've worked out what you are trying to do and what is going wrong...

The $pattern you were using is incorrect... you can use the same for both your regular expression matches.

Hopefully this will work for you:
Code
<br /><?php<br /><br />$filename ="wdfw_data.txt";<br />$handle= fopen($filename,'w');<br />$url="http://www.wdfw.wa.gov/fish/regs/fishregs.htm";<br />$result = shell_exec("wget -q -O - $url");<br /><br />$contents = Implode("", File($url));<br />preg_match_all("|<a\b([^>]+)>(.*?)</a>|i", $contents, $arrayoflinks);<br /><br />$x=1;<br />$pattern = "/regchng/i";<br />$replacement = "http://www.wdfw.wa.gov/fish/regs/regchng";<br /><br />while(List(,$link) = Each($arrayoflinks[0])){<br />        if (preg_match ($pattern, "$link")) {<br />                if($x<11){<br />                        $link = preg_replace($pattern, $replacement, $link);<br />                        $resulting_data .= "$link<br>";<br />                }<br />                $x++;<br />        }<br />}<br /><br /><br /><br />fputs($handle, $resulting_data);<br />fclose($handle);<br /><br />?><br />
Posted By: smilesforu Re: php relative output problem - 01/12/2004 6:48 AM
thanks..
© UBB.Developers