Jump to content

Recommended Posts

I'm trying to change a font color html code once my preg_match_all reads the file. Now the code only shows up when a winner has been posted for that tour. Otherwise it's not visible. So I want to search the preg results which is $matches, for the "font color=3FFF5E" and replace it with "font color=FFFFFF". If the code is not found, continue what it was doing. Here's what I THOUGHT might work. lol

 

<?php 
$html = file_get_contents(
'http://www4.igl.net/cgi-bin/tourney/gencalendar.cgi?path=crazyhouse');
preg_match_all('|"#0000AA">(.*?)<font size=1 color=yellow face=Arial>(.*?)</a><br><font size=1 color=white face=Arial>(.*?)</td>|is',$html,$matches,PREG_SET_ORDER);
$pattern = 'color=3FFF5E';
$replace = 'color=FFFFFF';


echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"175px\">";
foreach ($matches as $match){
preg_replace($pattern, $replace, $match[0]);
echo "<tr><td class=\"caltable\">$match[1]<font color=#FFFFFF class=\"callinkfnt\">$match[2]</font></a><br>$match[3]</tr></td>";
}
echo "</table>";

?>

 

I tried to seperate that code with preg_match_all and change the color there, as I did with the other font code you see. The problem is, it won't show any of the entries, if that code doesn't show up to begin with. Bad results. I do know that the change will take place in $match[3], if that helps at all. I tried to change 0 to 3 but didn't work.

Thanks for the help in advance.

I fixed it. Instead of messing with preg, i used str_replace on the file_get_contents. Changed it before it got chopped up in preg_match.

<?php 
$pattern = "color=3FFF5E";
$replace = "color=FFFFFF";
$html = file_get_contents(
'http://www4.igl.net/cgi-bin/tourney/gencalendar.cgi?path=crazyhouse');
$html = str_replace($pattern, $replace, $html);
preg_match_all('|"#0000AA">(.*?)<font size=1 color=yellow face=Arial>(.*?)</a><br><font size=1 color=white face=Arial>(.*?)</td>|is',$html,$matches,PREG_SET_ORDER);

echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"175px\">";
foreach ($matches as $match){
echo "<tr><td class=\"caltable\">$match[1]<font color=#FFFFFF class=\"callinkfnt\">$match[2]</font></a><br>$match[3]</tr></td>";
}
echo "</table>";

?>

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.