2015-02-06 55 views
-5

我有這個URL爲報廢:example.com/upload/produse/epilatoare/SE810%20Face.jpg?maxwidth=800 & maxheight = 800 我想刪除所有字符後.jpg,我不知道如何做到這一點。如何刪除文本後擴展名爲.jpg刮 - php

刮網站的代碼是:

if(isset($this->request->post['image_scrapper'])){ 
       $imageQuery = $xpath->query("//div[@id='fancybox-content']//img/@src"); 

       if($imageQuery->length > 0){ 
        foreach ($imageQuery as $key => $image){ 
         $extensie = end((explode('/', $image->nodeValue))); 
         $extensie = end((explode('.', $extensie))); 
         $model = preg_replace("/[^a-zA-Z0-9 -\/]+/","",trim($this->request->post['model'])); 
         $imageName = str_replace(" ","-",trim($this->request->post['product_description']['1']['name'])); 
         $imageName = preg_replace("/[^a-zA-Z0-9 -]+/","",$imageName); 
         $imageName .= "-".preg_replace("/[^a-zA-Z0-9 -]+/","",$model); 
         $imageName = strtolower($imageName); 
         $imageName = preg_replace("/[-]+/","-",$imageName); 
         $imageName .= '-'.rand().'.'.$extensie; 
         $imageName = 'data/'.$imageName; 

         copy($image->nodeValue, DIR_IMAGE.$imageName); 
         if($key == '0'){ 
          $this->model_catalog_product->firstImage($product_id, $imageName); 
         }else{ 
          $this->model_catalog_product->aditionaleImage($product_id, $imageName); 
         } 
        } 
       }else{ 
        if(isset($this->session->data['error'])){ 
         $this->session->data['error'] .= ' Produsul nu are imagini'; 
        }else{ 
         $this->session->data['error'] = 'Scrapper: Produsul nu are imagini.'; 
        } 
       } 
      } 

請幫助我, 感謝

+0

找到''字符的索引,並使用'SUBSTR? ()'從這一點刪除所有內容。有點像'$ newstring = substr($ string,0,strpos($ string,'?'));' – Cyclonecode 2015-02-06 02:27:21

+0

我的網址是:example.com/upload/produse/epilatoare/SE810%20Face.jpg?maxwidth=800&maxheight= 800 – 2015-02-06 03:52:32

+0

但我想要清楚的地址:example.com/upload/product/epilatoare/SE810%20Face.jpg – 2015-02-06 03:52:51

回答

0

試試這個:

$yourImage = substr($yourImage, 0, strpos($yourImage','.jpg')); 
+0

這部分strpos($ yourImage','。jpg')'應該至少是'strpos($ yourImage,' .jpg')' – Cyclonecode 2015-02-06 02:29:50

+0

謝謝,但我想請問,如何修改這個查詢乾淨的網址:$ imageQuery = $ xpath-> query(「// div [@ id ='fancybox-content'] // img/@ SRC「); – 2015-02-06 04:06:19