' not showing proberly pls help me

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    ' not showing proberly pls help me

    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 Code:
    <?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";
    }
    ?>

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

    PHP Code:
    <?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('&amp;#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 '

    sigpic
    alt='coding-talk.com!!' />';
    echo 'Sharing Is Caring!';
    } else {
    echo '

    alt='the username GHOST has been comprimised!' />';
    echo 'OMG SOMEBODY HELP ME!!';
    }
    ?>

    Comment


      #3
      why use string replace? its unreliable in ds case...

      try this (Since data from google is safe enuf)

      $tittle = html_entity_decode($info->title->attributes()->data);

      PHP: html_entity_decode - Manual
      I need some facebook likes, can you please help me
      http://facebook.com/softwarefreakin
      I noticed social media is really powerful
      Well DONE is better than well SAID

      Comment


        #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 Code:
        <?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
        Last edited by Ghost; 05.08.12, 05:50.
        <?php
        include ('Ghost');
        if ($Post == true) {
        echo '

        sigpic
        alt='coding-talk.com!!' />';
        echo 'Sharing Is Caring!';
        } else {
        echo '

        alt='the username GHOST has been comprimised!' />';
        echo 'OMG SOMEBODY HELP ME!!';
        }
        ?>

        Comment


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

          Comment

          Working...
          X