TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   preg_match problem. (http://www.talkphp.com/general/3993-preg_match-problem.html)

paulOr 02-23-2009 11:35 AM

preg_match problem.
 
PHP Code:

<?php

        $domain 
"http://twitter.com/paulor";

        
$ch curl_init() or die(curl_error());
        
curl_setopt($chCURLOPT_URL,$domain);
        
curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
$data1=curl_exec($ch) or die(curl_error());
        echo 
curl_error($ch);
        
curl_close($ch);

        
$regex '/<span id="following_count" class="stats_count numeric">(.+?)</span>"/';
        
preg_match($regex,$data1,$match);
        echo 
$match[1];

?>

Getting this error:
Quote:

Warning: preg_match() [function.preg-match]: Unknown modifier 'p' on line 15
line 15 is the regex btw

anyone know whats wrong?

Salathe 02-23-2009 11:50 AM

The regex pattern contains the string </span>. Since your delimiter is the forward slash, the pattern parser tries to stop read a pattern at the second forward slash which in this case is actually part of the closing span tag and not really the end of your pattern! Since the parser thinks the pattern has ended at that forward slash, it starts looking for modifiers. s is a valid one (which is why no error is raised there) but p isn't.

Solutions:
1. Use a different delimiter which won't be used in your pattern (popularly tilde ~mypattern~modifiers).
2. Escape the delimiter in your pattern: </span> becomes <\/span>

paulOr 02-23-2009 11:52 AM

thank you sir!

Salathe 02-23-2009 12:14 PM

Also, it's not really related to the question but you can get the follower information through Twitter's API: http://twitter.com/users/show/paulor.xml


All times are GMT. The time now is 07:48 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0