RE: [PHP] ereg() not matching same text each time script is run...
| From: | John Holmes | Date: | Wed, 24 Apr 2002 01:53:49 +0000 |
| Subject: | RE: [PHP] ereg() not matching same text each time script is run... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-94280@lists.php.net to get a copy of this message | ||
Someone gave me the preg_match equivalent
preg_match( '/([-_a-z]+)\.([a-z]+)$/i', $row['site'], $match2 );
I tried that and it took care of the problem, as far as I can tell.
To me, that narrows it down to a problem (bug?) with ereg... anyone else
have any ideas?
---John Holmes...
> -----Original Message-----
> From: John Holmes [mailto:holmes072000@charter.net]
> Sent: Tuesday, April 23, 2002 6:01 PM
> To: php-general@lists.php.net
> Subject: [PHP] ereg() not matching same text each time script is
run...
>
> Okay...I'm really at a loss for this...
>
> (PHP 4.0.6 on Redhat Linux)
>
> I've written a little script that shows the top referrers for
> http://www.falkware.com. Problem is...the script is supposed to
> take
> "www.domain.com" and strip out only the "domain" to show. It does
this,
> but only some of the time. I can't figure out a pattern to it, but
> sometimes the ereg will match "domain" and sometimes it won't... ??
The
> data is always the same because it's coming from a database. what
gives?
>
>
> Here is the code. This is the same exact code that is running on
> http://www.falkware.com right now. Referrer script is on left
> hand
side
> near the bottom. Refresh the screen and you'll see how it changes
> (maybe?). You can see I've added in some HTML comments to echo out
what
> the "site" from the database is, and what was matched.
>
> If anyone can help me out, it's greatly appreciated. I must be going
> crazy or something.... You can see the same question and code at
>
> http://forums.devshed.com/showthread.php?s=&threadid=34534&forumid=5.
> The PHP code has syntax highlighting on it, so it may be easier to
read
> there.
>
> The lines in question are:
> @eregi("([-_a-z]+)\.([a-z]+)$",$row[site],$match2);
> $name = $match2[1];
> How, if $row[site] is the same because it's pulled from a database,
can
> the ereg match the domain some of the time, and not match it during
> other times...?
>
>
>
PHP:--------------------------------------------------------------------
> -
>
> //Display table of referers
> $referer_query = "SELECT ID, site, count,
> DATE_FORMAT(last_visit,'%c/%e/%y %k:%i') AS last_visit,
> count/(TO_DAYS(NOW()) - TO_DAYS(first_visit)) AS visits_per_day FROM
> $table ORDER BY count DESC LIMIT " . (int)$num_sites;
> $referer_result = DB_query($referer_query);
>
> $returned_rows = DB_numRows($referer_result);
>
> if($returned_rows > 0)
> {
> if($_CST_VERBOSE) { COM_errorLog("**** Displaying top
> $returned_rows Sites ****", 1); }
>
>
> $retval .= "
> <table border='0' cellspacing='0' cellpadding='0'
> align='center' bordercolor='#afae8b' width='98%'>
> <tr>
> <td align=center><b><font face='verdana'
> size='1'>
<u>#</u>
> </font></b></td>
> <td align=center><b><font face='verdana'
> size='1'>
> <u>Site</u> </font></b></td>
> <td align=center><b><font face='verdana'
> size='1'>
> <u>Hits</u> </font></b></td>
> </tr>
> ";
>
> $site_count = 1;
>
> while($row = DB_fetchArray($referer_result))
> {
> if($_CST_VERBOSE) { COM_errorLog("**** Displaying Site
> #$site_count, $row[site] ****", 1); }
>
> unset($match2);
> $retval .= "<!-- Row[site] ==> " . $row["site"] . "
> -->";
>
> @eregi("([-_a-z]+)\.([a-z]+)$",$row[site],$match2);
> $name = $match2[1];
> $retval .= "<!-- Name matched ==> " . $name . " -->";
>
> if(strlen($name) == 0)
> {
> $name = $row[site];
> }
>
> $link = "http://" . $row[site] .
> "/";
>
> $retval .= "
> <tr>
> <td align=center><font face='tahoma' size='1'
> color='black'><strong> $site_count </strong></font></td>
> <td align=center>
> <a href='$link' target='_blank'><font
> face='verdana'
> size='1'><strong> $name </strong></font></a>
> </td>
> <td align='center'><font face='verdana'
> size='1'><strong> $row[count] </strong></font></td>
> </tr>
> ";
> $site_count++;
>
> if($show_time == 1)
> {
> $retval .= "<tr><td colspan='3'
> align='right'><font
> face='verdana' size='1' color='#999999'>Last:
> $row[last_visit]</td></tr>";
> }
> if($show_posts == 1)
> {
> if($row[visits_per_day] <= 0)
> {
> $row[visits_per_day] = $row[count];
> }
> $retval .= "<tr><td colspan='3'
> align='right'><font
> face='verdana' size='1' color='#999999'>Per Day:
> $row[visits_per_day]</td></tr>";
> }
> }
> $retval .= "</table>";
> }
> else
> {
> $retval .= "No referers yet.";
> }
>
> if($_CST_VERBOSE) { COM_errorLog("**** Leaving
phpblock_top_referer
> in lib-custom.php ****", 1); }
>
> return $retval;
>
>
------------------------------------------------------------------------
> --------
>
> When I run the page and look at the source, one time I'll get
>
> <!-- Row[site] ==> www.luclinks.com --><!-- Name matched ==> -->
>
> for the comments, and the next time it's run I'll get:
>
> <!-- Row[site] ==> www.luclinks.com --><!-- Name matched ==> luclinks
> -->
>
> ?? Like I said, I can't find a pattern to it though. I'm going to try
> out some other regular expressions...maybe that'll do the trick.
> Suggestions are welcome.
>
> Here is a sample of the table that the data is coming from:
>
>
code:-------------------------------------------------------------------
> --
> SELECT * FROM referer ORDER BY count DESC LIMIT 10;
>
> ID Site Count First_Visit Last_Visit IP
> 8 www.rubberanchovies.com 4133 2001-10-01 20020422190944
172.180.87.191
> 10 www.iwantanewgirlfriend.com 3413 2001-06-01 20020420133309
> 204.97.227.50
> 6 www.slapass.net 3068 2001-11-01 20020418170024 63.230.236.97
> 12 www.americanjackass.net 2463 2001-06-01 20020422143828
192.187.17.132
>
> 323 www.luclinks.com 2454 2002-01-22 20020329035137 172.141.93.71
> 13 www.validatethis.com 978 2002-01-01 20011229161124 2
> 20 www.geocities.com 734 2002-01-01 20020420013724 63.225.246.25
> 32 www.nethitters.com 634 2002-01-01 20020420110423 12.237.218.113
> 18 www.network-underground.net 626 2002-01-01 20011229161124 2
> 19 omniflare.devfx.org 594 2002-01-01 20011229161124 2
>
------------------------------------------------------------------------
> ---
>
>
> TIA,
>
> ---John Holmes...
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php