sınıf yöntemi ile sorun - bu foreach döngüsü içinde işe alınamıyor - php

1 Cevap php

I wrote the class Link which has a method shortTolong() this should return the real URL for a shortend url by returning the 'location' response header. i tested it and it works OK here is the code

public function shortTolong()
    {
        $urlMatch = array();
        $ch = curl_init();

        $options = array
        (
            CURLOPT_URL=>$this->getUrl(),
            CURLOPT_HEADER=>true,
            CURLOPT_RETURNTRANSFER=>true,
            CURLOPT_FOLLOWLOCATION=>false,
            CURLOPT_NOBODY=>true);
        curl_setopt_array($ch, $options);
        $server_output = curl_exec($ch);
        preg_match_all(LINK, $server_output,&$urlMatch,PREG_SET_ORDER);
        if($urlMatch)
        {
            foreach($urlMatch as $set)
            {
                $extracted_url = $set[2].'://'.$set[3];
            }
            return $extracted_url;
        }
        else
        {
            return $this->getUrl();
        }
    }

i i shorl url burada uzun bir instaed kodu bir sonucu olarak elde nedense Tahlil ned bu kısa adresler içeren yem girdileri almak için FeedParser kullanan diğer dosya üzerinde bu yöntemi kullanmaya çalıştığınızda sorun başlar:

foreach($parser->getItems() as $item)
{
    $idpreg = '/\d+/';
    preg_match_all($idpreg, $item['ID'],$statusid);
    $retweetid = ($statusid[0][1]);
    $datetime = $item['PUBLISHED'];
    $user = $item['AUTHOR']['NAME'];
    preg_match_all(LINK, $item['TITLE'], &$linkMatch);
    $final = $linkMatch[0][0];
    //if($linkMatch[0][0])
        echo '<p>';
        $link = new Link($final);
        echo $link->getUrl();
        echo '<br>';
        echo $link->shortTolong();
        echo '<br>';
        echo $user;
        echo '<br>';
        echo $retweetid;
        echo '</p>';


}

nedense i getUrl () ve shortTolong () için aynı sonucu almak ve ben bazı için bu bir hata olduğunu biliyorum.

any ideas why this is happening? Thanks

Edit- I added an error notice to the method with curl_eror i get this error massage: "Protocol http not supported or disabled in libcurl" as i said i tested this method from the and it's working fine as as stand alone in the same envoirment (no changes) i suspect it has somthing to do with FeedParser using curl too....

1 Cevap

i () url Döşeme gerektiğini ve bu sorunu çözmek gerektiğini düşünüyorum.