Jump to content

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>

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.