Jump to content

etrader

Members
  • Posts

    315
  • Joined

  • Last visited

    Never

Posts posted by etrader

  1. I want to create a xml-based rss which is readable by RSS readers

    <?xml version="1.0"?>
    <rss version="2.0">
      <channel>
        <title>Title</title>
        <link>http://link.com/</link>
    

     

    How I can write php strings from a php file into it as

    <item>
          <title><? echo $title ?></title>
          <link><? echo $link ?></link>
          <description><? echo $description ?></description>
          <pubDate><? echo $date ?></pubDate>
          <guid><? echo $id?></guid>
        </item>
    

     

     

     

  2. I put the javascript code of ad into a file named ad.html, then call it in php by

    $ad = file_get_contents("http://mysite.com/ad.html");
    echo $ad;

    But this does not work for file_get_contents("/ad.html")

     

    Is there a way to avoid writing the domain name, and just getting the ad from the file in the root folder?

  3. I used the following code to convert the length in seconds to min:second format

    $sec=$duration % 60;
    if ($sec=="0"){
    $min=$duration/60;
    $duration=''.$min.':00';
    }else{
    $min=(($duration-$sec)/60);
    $duration=''.$min.':'.$sec.'';
    }

    everything is OK, but it shows 35:5 instead of 35:05. I mean it disregards the first 0 when the second is 1-digit.  :-\

     

  4. I want to get suggested keywords from yahoo api service. When xml file is empty (no keyword), it gives error. To resolve this problem I used this code:

    if (file_exists('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2')) {
    $xmlmetades = simplexml_load_file('http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?appid=YahooDemo&query=Madonna&results=2');
    }
    

     

    Since it is not a normal .xml file, it is always considered no file, and return nothing.

  5. I have a foreach parsing as

    foreach ($posttags as $tag) {
    $test = $tag->name;
    $pattern = "/something/";
    if(preg_match($pattern, $test)) {
    $test2 = "$test is $test";
    echo $test2;
    }
    }
    

     

    I selected those containing a given word, but I do not know how to remove duplicates to have uniqueness. I was unable to use array_unique, as I am within a foreach loop.

  6. I have a file containing lines (I mean elements separated by <br>). How I can put these lines into an array, but only those which has a given phrase.

     

    Example file

    This is the first line<br>
    Second line is here<br>
    something else<br>
    something else<br>
    something more<br>

     

    I want to catch only lines which contain the word "something" and make an array.

  7. Youtube has an advanced api to deliver xml; but when I try to parse its xml, it is not well-defined. I want to get "average rating" for a given video, but simple xml load disregard this section:

    $xml = simplexml_load_file('http://gdata.youtube.com/feeds/mobile/videos/wZ252E282go');
    print_r($xml);

     

    How can I put the value of "average rating" into an string to echo?

  8. I tried to parse wikipedia xml api by different methods, but I was unsuccessful  :'( Even the curl method did not work

        $url = "http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Wikipedia&rvprop=timestamp|content";
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
        curl_setopt($ch, CURLOPT_POST, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_NOBODY, FALSE);
        curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
        curl_setopt($ch, CURLOPT_REFERER, "");
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2. Gecko/20100722 Firefox/3.6.8");
        $page = curl_exec($ch);
        $xml = simplexml_load_string($page);
    print_r($xml);

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.