Jump to content

phase a web site page.


redarrow

Recommended Posts

advance thank you

 

if i wanted to get info from  a web site from <p> to </p> how please.

 

my poor example.

<?php

$url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm");
$result=preg_match_all("#(<p>)(.?)(</p>)#",$url,$match);

print_r($match[0][1]);

?>

Link to comment
https://forums.phpfreaks.com/topic/153742-phase-a-web-site-page/
Share on other sites

does not work i get array() array() <<<<<<<<

 

got it going yee haaaaaaaa

<?php

$url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm");
$result=preg_match_all('/\<p\>(.*?)\<\/p\>/i',$url,$match);

foreach($match as $m){

echo $m;
}

?>

This one wrong why please need alteration lol.

 

no results.

<?php

$url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm");
$result=preg_match('/\<div class\=\"mvb\"\>(.*?)\<\/p\>/i',$url,$match);

foreach($match as $m){

echo $m;
}

?>

no see the web site in question trying to get all the football results

 

tried this.

 

no joy.


<?php

$url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm");
$result=preg_match('/\<div class\=\"pvtb\"\>\<b\>Barclays Premier League\<\/b\>\<\/div\>(.*?)\<\/p\>/i',$url,$match);

foreach($match as $m){

echo $m;
}

?>

I just tried this and it worked:

 

<?php
$url = '<div class="pvtb"><b>Barclays Premier League</b></div>hello</p>';
//$url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm");
preg_match('/\<div class\=\"pvtb\"\>\<b\>Barclays Premier League\<\/b\>\<\/div\>(.*?)\<\/p\>/i',$url, $matches);
foreach($matches as $key => $value)
{
echo $value;
}

?>

 

So it must not be on the page.

get this lol

 

<div class="pvtb"><b>Barclays Premier League</b></div>hello</p>hello

 

your funny

 

no result.

 

<?php
$url=file_get_contents("http://news.bbc.co.uk/sport1/hi/football/results/default.stm");

preg_match('/\<div class\=\"pvtb\"\>\<b\>Barclays Premier League\<\/b\>\<\/div\>(.*?)\<\/p\>/i',$url, $matches);

foreach($matches as $key => $value)
{
   echo $value;
}

?>

 

What's up with all the escaping? Double quotes, angle brackets and equals signs aren't special RegEx characters. And use a different delimiter than the forward slash to get rid of even more escaping! Not that it would match what the OP is actually looking for, but

 

'/\<div class\=\"pvtb\"\>\<b\>Barclays Premier League\<\/b\>\<\/div\>(.*?)\<\/p\>/i'

 

can be written as

 

'~<div class="pvtb"><b>Barclays Premier League</b></div>(.*?)</p>~i'

Meh, I just escape everything to be sure. And what difference does using a ~ do, if you don't mind me asking?

 

Maybe I was a bit harsh, but my eyes bleed seeing all those slashes :) I often use a ~ as delimiter since I never use that character inside the regex pattern, and therefore never have to escape it. Much like I often single quote HTML strings, so I don't have to escape the double quotes within.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.