Jump to content

PHP find text from another page between tags


Jnerocorp

Recommended Posts

Hello,

 

I would like to use PHP to capture any text between tags so what I want to do is

 

Get the text between:

 

<tbody>
<tr class="">
<td width="153">
<img alt="live_" src="/global/support/PublishingImages/global/live_.png"></td>
<td class="last"><p>Service is up and running.</p></td>
</tr>

<tr><td width="153"><img alt="marketplace_" src="/global/support/PublishingImages/global/marketplace_.png"></td>

<td class="last"><p>Service is up and running.</p></td>

</tr><tr><td width="153"><img alt="account_" src="/global/support/PublishingImages/global/account_.png"></td>

<td class="last"><p>Service is up and running.</p></td>

</tr><tr><td width="153"><img alt="matchmaking_" src="/global/support/PublishingImages/global/matchmaking_.png"></td>

<td class="last"><p>Service is up and running.</p></td>

</tr>
</tbody>

 

so what I want is everything between

 

"<td class="last"><p>" and "</p></td>"

 

as you can see it shows up so i dont know if its possible to get them as a variable like this:

 

$match[0]

$match[1]

$match[2]

$match[3]

 

it is from another url from another site so it would have to read it from another url and retrieve the conents does anyone know if this is possible?

 

-John

didnt work

 

i tried it like this:

 

<?php

$html = "WEBSITE URL HERE";
preg_match_all('%<td class="last"><p>(.*?)</p></td>%', $html, $match, PREG_PATTERN_ORDER);
$match = $match[1];
foreach($match as $matches){
echo $matches;
}

?>

 

and it does nothing

@teamatomic

 

I tried your code:

 

<?php

$file=file_get_contents("http://support.xbox.com/support/en/us/nxe/xboxstatus.aspx");
preg_match('~\<td class="last"><p>(.+?)</p></td>~i',$file,$matches);
$found=trim($matches[1]);

echo "$found<P>";
echo "<pre>";
print_r($matches);

?>

 

and its returning this:

 

Array
(
)

 

Code is not working :(

Well the url your using doesn't have

<td class="last"><p>
in it so, you could say it is working..

try this

 

$html = file_get_contents("http://support.xbox.com/support/en/us/nxe/xboxstatus.aspx");
preg_match_all('%</td><td><p>(.*?)</p></td></tr><tr>%', $html, $match, PREG_PATTERN_ORDER);
$match = $match[1];
foreach($match as $matches){
  echo "$matches<BR />\n";
}

well now its grabbing 3 of them but not all 4 and I cant control each one I need to be able to do it like this:

 

echo "Xbox Live: ". $match[0] ."";

echo "Xbox Live Marketplace: ". $match[1] ."";

echo "Xbox Live Billing: ". $match[2] ."";

echo "Xbox Live Match Making: ". $match[3] ."";

 

sorry to be such a hassle but im still trying to understand this stuff

No worries

remove the last <tr>

so change

preg_match_all('%</td><td><p>(.*?)</p></td></tr><tr>%', $html, $match, PREG_PATTERN_ORDER);

to

preg_match_all('%</td><td><p>(.*?)</p></td></tr>%', $html, $match, PREG_PATTERN_ORDER);

 

Translation

Find </td><td><p> then

(.*?) capture everything until

</p></td></tr>

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.