Jump to content

Preg_match error


hauni

Recommended Posts

Alright, this code of mine is a bit weird.

When I run it at localhost, it works fine,

but at on ce I upload it to 000webhost, I get errors. I don't know why, since I'm much of a newbie.

 

The error is:

Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '>' in /home/a5223586/public_html/members.php on line 17

 

Alright, and here comes the code, alright:

 

<?php

$ch = curl_init("http://www.tibia.com/community/?subtopic=guilds&page=view&GuildName=Society+of+the+Black+Rose");    
curl_setopt($ch, CURLOPT_HEADER, 0);    
curl_setopt($ch, CURLOPT_POST, 1);   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
  $output = curl_exec($ch);       
curl_close($ch);
//echo '<pre>'.htmlspecialchars($output).'</pre><hr/>';
preg_match_all('/name=[^"]+">([^><]+)<\/A>/', $output, $matched);


$fp = fopen("http://www.tibia.com/community/?subtopic=whoisonline&world=Antica","r");
while (feof($fp) != 1)
$text= $text.stripslashes(fgets($fp,10000)); str_replace("+", " ", $text);
?>
<div id="code">
<h3>
<?php
$text= $text.stripslashes(fgets($fp,10000));


foreach ($matched[1] as $value){
if (strpos($text, $value) > 1) {

$online .= $value. " <b><font color='green'>is online</font></b> <br>"; 
}
else 
{

$offline .= $value. " <b><font color='red'>is offline</font></b> <br>";
}
}    
echo  $online . $offline;



?>
</h3>
</div>
<?

fclose($fp);

?>

 

Please hellp me on this, the script is very important!

Thank you.

 

Regards,

 

 

Link to comment
Share on other sites

Uhm, something I missed.

Line 17 would be : the string:

preg_match_all('/name=[^"]+">([^><]+)<\/A>/', $output, $matched);

 

Here's my take.

 

- When you deal with forward slashes in your pattern, I would use something other than a / delimiter, just to avoid escaping those slashes (my fav is the # character.. but of course, you can use something else if you want).

- You may want to use the i modifier so that the pattern is case insensitive.. Otherwise, if the code your pattern is looking through has upper or lowercase characters that your pattern doesn't have, and your pattern is case sensitive, you will miss out on a match that should be done.

- You may be trying to do too much in your pattern..(I too am guilty of this from time to time). The main thing you are interested in capturing (according to your pattern if I understand this correctly), is everything between the <a> tag and the closing </a>, correct? Here is what I came up with...

 

preg_match_all('#<a[^>]*>(.+?)</a>#i', $output, $matched);

 

As a result, the capture $1 *should* grab everything between the opening and closing <a></a> tags (I haven't tested this code). If the pattern is to check against code across multiple lines, you may need to add an 's' next to the i modifier (this matches newlines as well, as by default, the dot character matches any character (except newlines).

 

I have to admit though.. when I looked over your original pattern, I fail to see any > character being treated as a modifier. I am confused by this admittedly.

 

In any case, hope any of this helps out..

 

Cheers,

 

NRG

Link to comment
Share on other sites

Ah, thanks :D

However, when I run the new code on localhost it works, but it adds some stuff that should not be there, and well, when I run it at the webhost it doesn't show anything at all.

 

If anyone has time and effort, it would be very kind to take a good ook into this script and help me figure it out.

 

All help is greatly appreciated.

 

Thank you!

 

My msn is hauni_hauni@hotmail.com if anyone wishes to take it more directly, whatever you wish.

 

Regards,

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.