Log in

View Full Version : read remote tag in remote content



zodehala
04-07-2013, 08:16 PM
i can read remote tag but just one like following



function get_title($url)
{
$title = '';
$handle = @fopen("$url", "r");

if ($handle) {
$i=0;
while (!feof($handle)) {
$i++;
$buffer = fread($handle, 8192);
$buffer = preg_replace("/\n|\r/", "", $buffer);
if (preg_match('/<li>(.*?)<\/u>/i', $buffer, $matches)) {
$title = $matches[$i];
break;
}
}
fclose($handle);
}
return $title;
}

echo get_title("http://natural-fertility-info.com/fertility-herbs");



but how can i read all data which is between <li><strong><u> and </u> in remote content

traq
04-07-2013, 10:52 PM
preg_match_all( "#<li><strong><u>([^(</u>)]*)</u>#ui",$buffer,$matches );

the results you're looking for will be in $matches[1].

zodehala
04-08-2013, 11:26 AM
i change it into following but values is in html tags


echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
function get_title($url)
{
$title = '';
$handle = @fopen("$url", "r");

if ($handle) {
while (!feof($handle)) {
$buffer = fread($handle, 8192);
$buffer = preg_replace("/\n|\r/", "", $buffer);
if (preg_match("#<li><strong><u>([^(</u>)]*)</u>#ui", $buffer, $matches)) {
foreach ($matches as $a=>$b){
echo $b."<br/>";
break;
}
}
}
fclose($handle);
}
return $title;
}

echo get_title("http://natural-fertility-info.com/fertility-herbs");


source code is like following



<li><strong><u>Black Cohosh</u><br/><li><strong><u>Maca</u><br/><li><strong><u>Shatavari</u><br/><li><strong><u>Yarrow</u><br/><li><strong><u>Evening Primrose Oil</u><br/><li><strong><u>Shatavari</u><br/><li><strong><u>Ashwagandha</u><br/><li><strong><u>Castor Oil</u><br/><li><strong><u>Echinacea</u><br/><li><strong><u>Goldenseal</u><br/><li><strong><u>Red Raspberry</u><br/>


how can i print just value ??

traq
04-08-2013, 02:30 PM
i change it into following but values is in html tags

[...]

how can i print just value ??

re-read my post.

the results you're looking for will be in $matches[1].