hauni Posted October 7, 2008 Share Posted October 7, 2008 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, Quote Link to comment Share on other sites More sharing options...
hauni Posted October 7, 2008 Author Share Posted October 7, 2008 Uhm, something I missed. Line 17 would be : the string: preg_match_all('/name=[^"]+">([^><]+)<\/A>/', $output, $matched); Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted October 7, 2008 Share Posted October 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted October 7, 2008 Share Posted October 7, 2008 Oh, I forgot, you'll be looking for $matched[1] as the desired captured results... Example for test ouput code: echo '<pre>'; print_r($matched[1]); echo '</pre>'; Cheers, NRG Quote Link to comment Share on other sites More sharing options...
hauni Posted October 7, 2008 Author Share Posted October 7, 2008 Ah, thanks 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, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.