' not showing proberly pls help me

Started on the old forum in August 2012 · view the original in the archive · old links redirect here

4 replies · 517 views · started 14 years ago · 1 min read

3 participants
marv Newbie · 7 posts #1

Hi all im still a newbie in php and i am having a problem with a script im working on i trying to read news from googles news api but on the page display instead of a ' (Apostrophe) i get & #39; with the text output

ive tried to use str_replace to correct this but it seems it cant pickup the & #39;

Please help here is the code ive come up with below

<?php 
$api = simplexml_load_string(utf8_encode(file_get_contents("http://www.google.co.za/ig/api?news")));

foreach ($api->news->news_entry as $info)
{

#$tittle =  str_replace('& #39;',"'",$info->title->attributes()->data);
$tittle =  $info->title->attributes()->data;

echo "<h3>".$tittle."</h3> \n";
echo $info->snippet->attributes()->data."<br> \n";
echo $info->date->attributes()->data."<br> \n";
echo $info->source->attributes()->data."<br> \n";
#echo $info->num_related->attributes()->data."<br> \n";
#echo $info->url->attributes()->data."<br> \n";
#echo $info->cluster_url->attributes()->data."<br> \n";
echo "<br> \n";
}
?>
Ghost Senior · 366 posts #2

heres your fix. i used your str_replace method. i noticed while looking at the source that it actually produced. &#39; rather than ' so i just added the amp for you 😉

<?php  
$api = simplexml_load_string(utf8_encode(file_get_contents("http://www.google.co.za/ig/api?news"))); 

foreach ($api->news->news_entry as $info) 
{ 

$tittle =  str_replace('&#39;',"'",$info->title->attributes()->data); 
//$tittle =  $info->title->attributes()->data; 

echo "<h3>".$tittle."</h3> \n"; 
echo $info->snippet->attributes()->data."<br> \n"; 
echo $info->date->attributes()->data."<br> \n"; 
echo $info->source->attributes()->data."<br> \n"; 
#echo $info->num_related->attributes()->data."<br> \n"; 
#echo $info->url->attributes()->data."<br> \n"; 
#echo $info->cluster_url->attributes()->data."<br> \n"; 
echo "<br> \n"; 
} 
?>

tested and worked for me.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
Ghost Senior · 366 posts #4

i didnt even think about that when replying to the original poster.

your way is indeed better..

also to the original poster. i would recommend also doing it to the snippet function as the problem is there also

ive taking it upon myself to do the modding myself. here is softwarefreaks suggestion done to title. and also done to snippet. so the whole page looks better.

<?php  
$api = simplexml_load_string(utf8_encode(file_get_contents("http://www.google.co.za/ig/api?news"))); 

foreach ($api->news->news_entry as $info) 
{ 
$tittle = html_entity_decode($info->title->attributes()->data);
echo "<h3>".$tittle."</h3> \n";
$snippet = html_entity_decode($info->snippet->attributes()->data);
echo $snippet."<br> \n"; 
echo $info->date->attributes()->data."<br> \n"; 
echo $info->source->attributes()->data."<br> \n"; 
//echo $info->num_related->attributes()->data."<br> \n"; 
//echo $info->url->attributes()->data."<br> \n"; 
//echo $info->cluster_url->attributes()->data."<br> \n"; 
echo "<br> \n"; 
} 
?>

edited spelling mistake on poster name

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
marv Newbie · 7 posts #5

Thanks So Much Guys Ive just tested and its working Great ive Just Learned a new function Im very Greatful 🙂 Thanks again

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close