I am getting search results from a search engine in this script;
Code: Select all
<?php
$urlparam = $_GET['id'];
// get search results
$html = file_get_contents("http://vsearch.nlm.nih.gov/vivisimo/cgi-bin/query-meta?input-form=simple&v%3Asources=medlineplus-bundle&v%3Aproject=medlineplus&binning-state=&query=".$urlparam."&x=67&y=9");
$regex = "/<div class=\"document-header\"><a class=\"title\"(.+?) target=\"_/";
if (!preg_match_all($regex,$html,$matches))
return false;
$matches=$matches[1];
for ($i=0;$i<count($matches);$i++) {
$match=trim($matches[$i]);
$results[]= $match;
}
$expr = "/url=(.+?)rid/i";
foreach($results as $href) {
if (!preg_match($expr, $href, $tmpRes))
return false;
$urls[] = $tmpRes[1];
}
for ($i=0;$i<count($urls);$i++) {
$url=trim($urls[$i]);
$url=preg_replace ("/%3a%2f%2f/i","://",$urls[$i]);
$url= preg_replace ("/%2f/i","/",$url);
$url= preg_replace ("/%3f/","?",$url);
$url= preg_replace ("/%3d/","=",$url);
$url=preg_replace('/&/','',$url);
$url= preg_replace('/%26/','&',$url);
$sresults[]= $url;
}
print_r($sresults);Code: Select all
$url=preg_replace('/&/','',$url);
Array ( [0] => http%3a%2f%2fwww.nlm.nih.gov%2fmedlineplus%2fcancer.html&
all other preg_replace works fine but the last & is repalced by 'amp'
in the output
Array ( [0] => http%3a%2f%2fwww.nlm.nih.gov%2fmedlineplus%2fcancer.htmlamp
I have tried str_replace but it does not work as
I am using php 5.2.6 on wamp 2.0
Please help
Thanks in advance
Mehnaz