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
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;
}

?>

Link to comment
Share on other sites

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;
}

?>

Link to comment
Share on other sites

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;
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
}

?>

 

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.