|
|
Joined: Jan 2002
Posts: 674
Junior Member
|
Junior Member
Joined: Jan 2002
Posts: 674 |
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.htmbut returns a link like this in my pal box http://www.steelheader.net/ubbthreads/regchng/nov1903c.htmI do a include from the txt file... should be a easy fix but its beyond me. <?<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 />
|
|
|
|
Joined: Jan 2004
Posts: 2
Lurker
|
Lurker
Joined: Jan 2004
Posts: 2 |
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.
|
|
|
|
Joined: Jan 2004
Posts: 2
Lurker
|
Lurker
Joined: Jan 2004
Posts: 2 |
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: <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 />
|
|
|
|
Joined: Jan 2002
Posts: 674
Junior Member
|
Junior Member
Joined: Jan 2002
Posts: 674 |
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 5,833
Joined: January 2000
|
|
Forums63
Topics37,573
Posts293,925
Members13,849
|
Most Online5,166 Sep 15th, 2019
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|
|