Getting Google News RSS Feeds from selected Cities - php

I am fetching Google news from Google News RSS feed. The URL is
http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&topic=n&output=rss
This return all US titles.
[0] => Array
(
[title] => Transportation Safety Board Team Probes N.Y. Ferry Crash - Bloomberg
[link] => http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGDVYrS8J_SXHtPWyYXxxXyKkNaRw&url=http://www.bloomberg.com/news/2013-01-10/transportation-safety-board-team-probes-n-y-ferry-crash.html
[image] => //nt3.ggpht.com/news/tbn/t9HUK7dtkbtFrM/6.jpg
[site_title] => Bloomberg
[story] => The National Transportation Safety Board began an investigation of the rush-hour commuter ferry crash near Manhattan's financial district that sent passengers flying and injured dozens. The NTSB sent an 11-member “go team†to New York yesterday to ...
)
[1] => Array
(
[title] => Obama Cabinet may not meet his own diversity standards - Los Angeles Times
[link] => http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGSgKCy6djWVzzCkvphxbK-anvjlw&url=http://www.latimes.com/news/nationworld/nation/la-na-obama-administration-20130110,0,4200106.story
[image] => //nt2.ggpht.com/news/tbn/CtM74UExtG_E7M/6.jpg
[site_title] => Los Angeles Times
[story] => WASHINGTON — Wednesday's "photo of the day" on the White House website showed an unusual sight in Oval Office history — the president surrounded by top advisors, only half of whom are white men. The picture seemed calculated to counter criticism ...
)
[2] => Array
(
[title] => Chris Christie: Master of Disaster - TIME
[link] => http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNErxzRlmXjDZOAvqU0hMIwYspcnpg&url=http://swampland.time.com/2013/01/09/chris-christie-master-of-disaster/
[image] => //nt3.ggpht.com/news/tbn/XyB4G4Cfox0EOM/6.jpg
[site_title] => TIME
[story] => This morning on NBC's Today Show, Chris Christie reacted to being on the brand new cover of TIME. The full cover story will be available on time.com later today and on newsstands Friday. Gov. Christie was featured as one of 13 members in TIME's Class of ...
)
But I just want the news from California or XYZ. Is there a way to add a city name in parameter or any other solution? Thank you.

You need to just change value of ned and hl parameters in Url like following url you can see different news .
http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&topic=n&output=rss
Spanish News
https://news.google.com/news/feeds?cf=all&ned=es_cu&hl=es&output=rss

Related

Find semantics words between different phrases

I try to find a way to define in PHP a semantic by comparing some phrases and find occurence for example i have something like
Array
(
[0] => Cats love Mouse Car Dog Fish
[1] => Pictures Cats Some Text Mouse
[2] => Game of thrones 2015 Series
[3] => Stark Series lannister John Game of thrones
[4] => Pop Rock David Bowie Music
[5] => David Great Lower Text Bowie
)
And I expected for the output
Array
(
[0] => Cats Mouse
[1] => Game of thrones Series
[2] => David Bowie
)
How can I proceed ?

Regex to ignore match if content isn't numeric?

I wrote a regex to parse out a string in the form of:
Job Title (<numeric job number>) Location, State, Country
with this:
(?P<jobTitle>[a-zA-Z0-9,\:\/\s]+)[\s]+\((?P<jobCode>[0-9]+)\)[\s]+(?P<location>[a-zA-Z0-9,\s]+)
But I ran into a problem when a job came in this form instead:
Job Title (extra information) (<numeric job number>) Location, State, Country
So my question is, how can I take in everything before the numeric job number as the 'jobTitle', the numeric portion as the 'jobCode', and everything after that as the 'location'?
For example
Super Cool Job (12345) Cool Place, California, United States
jobTitle => Super Cool Job
jobCode => 12345
location => Cool Place, California, United States
Another Cool Job (Not in california) (54321) Paris, France
jobTitle => Another Cool Job (Not in california)
jobCode => 54321
location => Paris, France
You could be looking for something like:
(.*\S)\s+\((\d+)\)\s+(\S.*)
With this simple regex, your strings will be in Groups 1, 2 and 3
$jobs='Super Cool Job (12345) Cool Place, California, United States
Another Cool Job (Not in california) (54321) Paris, France';
$regex = '/^(?m)(.*?)\s+\((\d+)\)\s+(.*)$/';
if(preg_match_all($regex,$jobs,$matches, PREG_SET_ORDER)) {
echo "<pre>";
print_r($matches);
echo "</pre>";
}
OUTPUT:
Array
(
[0] => Array
(
[0] => Super Cool Job (12345) Cool Place, California, United States
[1] => Super Cool Job
[2] => 12345
[3] => Cool Place, California, United States
)
[1] => Array
(
[0] => Another Cool Job (Not in california) (54321) Paris, France
[1] => Another Cool Job (Not in california)
[2] => 54321
[3] => Paris, France
)
)
If you want to extract all the fields, you can use this:
^(?<title>\D+) \((?<id>\d+)\)(?: (?<desc>[^,]+),)? (?<city>[^,]+), (?<country>[^,]+)$

PHP Regex, Only getting back partial Results

I have the following PHP regex:
#<tr[\s\S]*?<a class="b1"[\s\S]*?<em[^>]*>([^<]*)[\s\S]*?stars_small_([0-9].[0-9])#
Which I am using on this site:
Gamespy
I get back this data:
[1] => Array
(
[0] => AC/DC Live: Rock Band Track Pack
[1] => Ace Combat 6: Fires of Liberation
[2] => All-Pro Football 2K8
[3] => Alone in the Dark
[4] => Armored Core 4
[5] => Army of Two
[6] => Army of Two: The 40th Day
)
[2] => Array
(
[0] => 3.5
[1] => 2.5
[2] => 3.5
[3] => 3.5
[4] => 2.5
[5] => 3.5
[6] => 3.5
)
This is what I am looking for, however I don't seem to be getting back all of the data. I should get the following Titles with scores. But for some reason I am only getting some of them.
AC/DC Live: Rock Band Track Pack
Ace Combat 6: Fires of Liberation
Afro Samurai
Alan Wake
Aliens vs. Predator
All-Pro Football 2K8
Alone in the Dark
Amped 3
Armored Core 4
Army of Two
Army of Two: The 40th Day
Assassin's Creed
Assassin's Creed II
Assassin's Creed: Brotherhood
Avatar: The Game
I have tested my regex here:
http://www.solmetra.com/scripts/regex/index.php
Using this HTML:
http://justpaste.it/20u5
Any help explaining why I am only getting back some of the results would be greatly appreciated. Thanks
Change the sub-pattern stars_small_([0-9].[0-9]) to stars_small_([0-9](?:\.[0-9])?) as some of the urls only have one digit in the SRC attribute of the IMG tag.

check if in_array php not working

I want to check a value in an array. If its not there it gets pushed to a new array. If the value is already there then its not added to the new value.
But with my code the checking of the value is not working.
Its still adding the array if the specific value is present.
I got this code:
foreach($user_movie_info['data'] as $movie) {
similar_text($movie_facebook_page['genre'], $movie['genre'], $percent);
if ($percent > 30) {
echo $movie_facebook_page['genre']. "" ."</br>";
echo $movie['genre']. "" ."</br>";
echo $percent. "" ."</br>";
echo "match! </br></br>";
// add all movie information to matched array, only if its not already present
if (!in_array($movie_facebook_page['name'], $matched_movies_array)) {
array_push($matched_movies_array, $movie_facebook_page);
}
} //foreach
If i print out the $matched_movies_array i got one array 2 times in it:
Array
(
[0] => Array
(
[about] => In theaters January 4th 2013 www.TexasChainsaw3D.com
[can_post] => 1
[description] => Lionsgate’s TEXAS CHAINSAW 3D continues the legendary story of the homicidal Sawyer family, picking up where Tobe Hooper’s 1974 horror classic left off in Newt, Texas, where for decades people went missing without a trace. The townspeople long suspected the Sawyer family, owners of a local barbeque pit, were somehow responsible. Their suspicions were finally confirmed one hot summer day when a young woman escaped the Sawyer house following the brutal murders of her four friends. Word around the small town quickly spread, and a vigilante mob of enraged locals surrounded the Sawyer stronghold, burning it to the ground and killing every last member of the family – or so they thought.
Decades later and hundreds of miles away from the original massacre, a young woman named Heather learns that she has inherited a Texas estate from a grandmother she never knew she had. After embarking on a road trip with friends to uncover her roots, she finds she is the sole owner of a lavish, isolated Victorian mansion. But her newfound wealth comes at a price as she stumbles upon a horror that awaits her in the mansion’s dank cellars…
With gruesome surprises in store for a whole new generation, TEXAS CHAINSAW 3D stars Alexandra Daddario, Dan Yeager, Tremaine ‘Trey Songz’ Neverson, Scott Eastwood, Tania Raymonde, Shaun Sipos, Keram Malicki-Sanchez, James MacDonald, Thom Barry, Paul Rae and Richard Riehle, along with special appearances from four beloved cast members from previous installments of the franchise: Gunnar Hansen (the original Leatherface), Marilyn Burns, John Dugan and Bill Moseley. The film is directed by John Luessenhop (TAKERS), from a screenplay by Adam Marcus & Debra Sullivan and Kirsten Elms, based on a story by Stephen Susco and Adam Marcus & Debra Sullivan and based on characters created by Kim Henkel and Tobe Hooper, and produced by Carl Mazzocone. Lionsgate presents a production and Main Line Pictures production.
[directed_by] => John Luessenhop
[genre] => Horror
[is_published] => 1
[produced_by] => Millennium Films
[release_date] => January 4th 2012
[screenplay_by] => Adam Marcus & Debra Sullivan and Kirsten Elms
[starring] => Alexandra Daddario, Dan Yeager, Tremaine ‘Trey Songz’ Neverson, Scott Eastwood, Tania Raymonde, Shaun Sipos, Keram Malicki-Sanchez, James MacDonald, Thom Barry, Paul Rae and Richard Riehle
[studio] => Lionsgate
[talking_about_count] => 62964
[username] => TexasChainsaw3D
[website] => www.texaschainsaw3d.com, twitter.com/lionsgatehorror, http://pinterest.com/lionsgatemovies/texas-chainsaw-3d, https://plus.google.com/u/0/+LionsgateMovies, http://instagr.am/p/Qpm0JMPtDr/
[were_here_count] => 0
[written_by] => based on a story by Stephen Susco and Adam Marcus & Debra Sullivan
[category] => Movie
[id] => 323192834416509
[name] => Texas Chainsaw 3D
[link] => http://www.facebook.com/TexasChainsaw3D
[likes] => 367992
[cover] => Array
(
[cover_id] => 4.14284428641E+14
[source] => http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash3/s720x720/530974_414284428640682_1806025466_n.png
[offset_y] => 0
)
)
[1] => Array
(
[about] => The official Facebook Page for The Shining | All work and no play makes Jack a dull boy.
[awards] => (1981) Saturn Award, Best Supporting Actor, Scatman Crothers
[can_post] => 1
[description] => Get The Shining at the WB Shop: http://bit.ly/shiningdvd
[directed_by] => Stanley Kubrick
[genre] => Horror, Suspense/Thriller
[is_published] => 1
[plot_outline] => All work and no play makes Academy Award-winner Jack Nicholson ("As Good As It Gets," "Batman"), the caretaker of an isolated resort, go way off the deep end, terrorizing his young son and wife Shelley Duvall ("Roxanne"). Master filmmaker Stanley Kubrick's ("Full Metal Jacket," "2001: A Space Odyssey") visually haunting chiller, based on the bestseller by master-of-suspense Stephen King ("The Stand," "Carrie," "The Shawshank Redemption"), is an undeniable contemporary classic. Newsweek Magazine calls this "the first epic horror film," full of indelible images, and a signature role for Nicholson whose character was recently selected by AFI for its' 50 Greatest Villains.
[produced_by] => Jan Harlan, Stanley Kubrick
[release_date] => 5/23/80
[screenplay_by] => Stephen King, Diane Johnson
[starring] => Jack Nicholson, Shelley Duvall, Danny Lloyd, Scatman Crothers
[studio] => Warner Bros.
[talking_about_count] => 5594
[username] => KubrickShining
[website] => http://bit.ly/shiningdvd
[were_here_count] => 0
[written_by] => Stephen King
[category] => Movie
[id] => 135347089926692
[name] => The Shining
[link] => http://www.facebook.com/KubrickShining
[likes] => 832526
[cover] => Array
(
[cover_id] => 2.24275514367E+14
[source] => http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash4/320182_224275514367182_46004854_n.jpg
[offset_y] => 85
)
)
[2] => Array
(
[about] => The official Facebook Page for The Shining | All work and no play makes Jack a dull boy.
[awards] => (1981) Saturn Award, Best Supporting Actor, Scatman Crothers
[can_post] => 1
[description] => Get The Shining at the WB Shop: http://bit.ly/shiningdvd
[directed_by] => Stanley Kubrick
[genre] => Horror, Suspense/Thriller
[is_published] => 1
[plot_outline] => All work and no play makes Academy Award-winner Jack Nicholson ("As Good As It Gets," "Batman"), the caretaker of an isolated resort, go way off the deep end, terrorizing his young son and wife Shelley Duvall ("Roxanne"). Master filmmaker Stanley Kubrick's ("Full Metal Jacket," "2001: A Space Odyssey") visually haunting chiller, based on the bestseller by master-of-suspense Stephen King ("The Stand," "Carrie," "The Shawshank Redemption"), is an undeniable contemporary classic. Newsweek Magazine calls this "the first epic horror film," full of indelible images, and a signature role for Nicholson whose character was recently selected by AFI for its' 50 Greatest Villains.
[produced_by] => Jan Harlan, Stanley Kubrick
[release_date] => 5/23/80
[screenplay_by] => Stephen King, Diane Johnson
[starring] => Jack Nicholson, Shelley Duvall, Danny Lloyd, Scatman Crothers
[studio] => Warner Bros.
[talking_about_count] => 5594
[username] => KubrickShining
[website] => http://bit.ly/shiningdvd
[were_here_count] => 0
[written_by] => Stephen King
[category] => Movie
[id] => 135347089926692
[name] => The Shining
[link] => http://www.facebook.com/KubrickShining
[likes] => 832526
[cover] => Array
(
[cover_id] => 2.24275514367E+14
[source] => http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash4/320182_224275514367182_46004854_n.jpg
[offset_y] => 85
)
)
)
I get this info from the open graph api from Facebook.
$matched_movies_array does not contain the movie names. So in_array will never pass.
Try something like:
$movieIds = array();
foreach($user_movie_info['data'] as $movie) {
similar_text($movie_facebook_page['genre'], $movie['genre'], $percent);
if ($percent > 30) {
echo $movie_facebook_page['genre']. "" ."</br>";
echo $movie['genre']. "" ."</br>";
echo $percent. "" ."</br>";
echo "match! </br></br>";
// add all movie information to matched array, only if its not already present
if (!in_array($movie_facebook_page['id'], $movieIds)) {
$movieIds[] = $movie_facebook_page['id'];
array_push($matched_movies_array, $movie_facebook_page);
}
} //foreach
Or maybe even better:
$id = $movie_facebook_page['id'];
if (!isset($matched_movies_array[$id])) {
$matched_movies_array[$id] = $movie_facebook_page;
}
The in_array() function doesn't work searching for a string in a multi-dimensional array. Take this for example:
$find = array("name" => "test");
$matches = array(array("name" => "test"), array("name" => "test2"));
echo (in_array($find['name'], $matches)) ? "found" : "not found";
echo "<br /><br />";
echo (in_array($find, $matches)) ? "found" : "not found";
The first echo is "not found", the second one is "found". You should use your entire $movie_facebook_page array as the needle.

PHP array and foreach help

I need some help with an array and a foreach loop,
I have an array that is data returned from a database, basically it is a list of titles and images associated with it, it looks a little like this,
Array
(
[0] => Array
(
[contentImageId] => 28
[contentImageName] => yellow.png
[contentImageType] => .png
[contentImagePath] => /var/www/bangmarketing.bang/media/uploads/contentImages/7/yellow.png
[isHeadlineImage] => 1
[contentImageDateUploaded] => 1265388055
[contentId] => 7
[dashboardUserId] => 0
[contentTitle] => Another Blog
[contentAbstract] => <p>This is another blog and it is shit becuase this does not work</p>
[contentBody] => <p>ioasfihfududfhdufhuishdfiudshfiudhsfiuhdsiufhusdhfuids</p>
[contentOnline] => 1
[contentAllowComments] => 0
[contentDateCreated] => 1265388034
[categoryId] => 1
[categoryTitle] => blogsss
[categoryAbstract] => <p>asdsdsadasdsadfdsgdgdsgdsgssssssssssss</p>
[categorySlug] => blog
[categoryIsSpecial] => 0
[categoryOnline] => 1
[categoryDateCreated] => 1266588327
)
[1] => Array
(
[contentImageId] => 31
[contentImageName] => sophie.jpg
[contentImageType] => .jpg
[contentImagePath] => /var/www/bangmarketing.bang/media/uploads/contentImages/9/sophie.jpg
[isHeadlineImage] => 1
[contentImageDateUploaded] => 1265713423
[contentId] => 9
[dashboardUserId] => 0
[contentTitle] => Bang appoints a new Senior Designer
[contentAbstract] => <p>Bang has appointed a new Senior Designer in the wake of a number of major client wins.</p>
[contentBody] => <p>After recently signing up clients including the National Trust and Propaganda, Bang has hired Sophie Smith to join its creative team.</p>
<p>Sophie brings over twelve years of extensive design experience in Bang's core market sectors, including social housing and public sector brands.</p>
<p>Sophie has significant experience of branding and strategic design projects for a broad range of clients, including HBoS, Harvey's, TKMaxx and Places for People.</p>
<p>Warren Watts Creative Director at Bang commented; "Sophie has already proven an invaluable addition to our growing studio. In only her second week, she helped produce the creative that led to the National Trust account win".</p>
[contentOnline] => 1
[contentAllowComments] => 0
[contentDateCreated] => 1265713155
[categoryId] => 8
[categoryTitle] => News
[categoryAbstract] => <p>The world at Bang Marketing moves fast, keep up to date w
[categorySlug] => news
[categoryIsSpecial] => 0
[categoryOnline] => 1
[categoryDateCreated] => 1265283717
)
[2] => Array
(
[contentImageId] => 32
[contentImageName] => selectadna.jpg
[contentImageType] => .jpg
[contentImagePath] => /var/www/bangmarketing.bang/media/uploads/contentImages/10/selectadna.jpg
[isHeadlineImage] => 1
[contentImageDateUploaded] => 1265713937
[contentId] => 10
[dashboardUserId] => 0
[contentTitle] => Bang client experiences growth
[contentAbstract] => <p>Selectamark, the UK's leading asset protection specialist recorded its best figures for five years in 2008.</p>
[contentBody] => <p>The results were released during an extremely challenging economic climate, and just over 12 months into the organisation's relationship with Bang.</p>
<p>Bang has been working on developing Selectamark's range of product brands, which include the UK's leading asset tracking and labelling system Selectamark, and second generation forensic marking system, SelectaDNA. Despite gloomy national economic forecasts, Selectamark has enjoyed an extremely successful start to 2009 – picking up several major new clients in February, and with discussions taking place to expand operations beyond the UK and Netherlands to Germany and New Zealand.</p>
<p>Chris Garratt, Marketing Director at Bang Marketing Ltd explained "Selectamark adopted a well planned, coordinated and consistent strategy in 2008, and the results speak for themselves.</p>
<p>"Due to the success last year and the forecasts for increased levels of acquisitive crime we're hoping Selectamark's key products will enjoy similar growth in 2009".</p>
<p>Selectamark Security Systems provides DNA Forensic Marking products (SelectaDNA) and Visible Marking solutions (Selectamark and Logomark) to prevent burglaries, theft from void properties, theft of boilers, and theft of valuable metals such as lead from roofs. Selectamark have supplied these Secured By Design crime prevention products to Police, local authorities and housing associations for 25 years.</p>
<p>The Selectamark system has now marked over 25 million items, and is patented and distributed world-wide. Visit www.selectadna.co.uk for product details.</p>
<p>James Brown, Sales Director at Selectamark said "We have been absolutely delighted with the work Bang has done for us. In a short space of time, the Bang team has created a wide range of extremely fresh and professional-looking sales and marketing material for us to use, as well as devising a detailed marketing strategy which has now been implemented. We would have no hesitation in recommending Bang to other organisations."</p>
[contentOnline] => 1
[contentAllowComments] => 0
[contentDateCreated] => 1265713888
[categoryId] => 8
[categoryTitle] => News
[categoryAbstract] => <p>The world at Bang Marketing moves fast, keep up to date w
[categorySlug] => news
[categoryIsSpecial] => 0
[categoryOnline] => 1
[categoryDateCreated] => 1265283717
)
)
As you can see the contentTitle changes, everytime but sometime is returns the same content title, I am looking for a way to add a divide between the returned data, if the content Title value changes?
Is this possible? and how? I am really struggling here.
Thanks
As you loop through, you can have a temporary variable to store the last displayed title
$lastTitle='';
foreach ($array as $record)
{
if ($lastTitle != $record['contentTitle'])
echo '<hr>';
$lastTitle = $record['contentTitle');
// display content from record
}
If I understand you correctly, you want to display a divider every time the contentTitle is different from the value it had in the last iteration.
You're making a kind of gallery here, aren't you?
If so, I would go about it like this:
$lastTitle = '';
foreach($yourArray as $value)
{
if(!$lastTitle || $lastTitle != $value['contentTitle'])
{
echo '<h2>' . $value['contentTitle'] . '</h2><hr />'; // Display divider
// Do some other stuff
}
$lastTitle = $value['contentTitle'];
// Display image or whatever you want to do
}

Categories