Remove the quotes around $data->status->text. You can use strpos() to check if $text contains the things you're looking for. If it does, store the id, store it and break :)
twiss
Veteran Poster
1,005 posts since Apr 2010
Reputation Points: 177
Solved Threads: 101
preg_match() could also be used.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
If you could give a sample of the xml file as well? Otherwise I'd be guessing.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
I got it to work with static text from the link you provided:
$xml = new SimpleXMLElement($content);
foreach ($xml->user as $data){
$text = $data->status->text;
if(strpos($text,'@me')!==false && strpos($text,'#RT')!==false){
$id = $data->status->id;
echo $id . " " . $text . "";
}
}
However, my php not set up to deal with opening files in https, so had to use a text input from said page.
I need to uncomment the;extension=php_openssl.dll line in php.ini
//HA HA just tried to edit my php.ini and found that the line was missing!!
Just added it to the file, uncommented it and restarted Apache.
The code now works for me on localhost (BTW I am using XAMPP for Windows 1.1.2.2, just in case you have the same problem).
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
How's this?
<?php
$xmldata = 'https://api.twitter.com/1/statuses/followers/bbcclick.xml';
$content = file_get_contents($xmldata);
$xml = new SimpleXMLElement($content);
foreach ($xml->user as $data){
$text = $data->status->text;
if(strpos($text,'@me')!==false && strpos($text,'#RT')!==false){
$id = $data->status->id;
$id = mysql_real_escape_string($id);
$text = mysql_real_escape_string($text);
$concat[] = "('$id','$text')";
}
}
if(isset($concat)){
$vals = implode(',',$concat);
mysql_query("INSERT INTO `data` ( `ID`, `text`) VALUES $vals");
}
?>
Not tested...
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
As long as you have a quote around each value, it shouldn't matter.
$concat[] = "('$id','$text')";
this places $text within quotes, so should be safe.
Are you saying that '#' stops the strpos?
Show the code you're using with connection statements (use xxx or similar instead of username/pw).
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Post your code perhaps? It's hard to guess the problem just by knowing there is one. Edit: oops, didn't see page 2 :)
twiss
Veteran Poster
1,005 posts since Apr 2010
Reputation Points: 177
Solved Threads: 101