我有这个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.';
}
}
}
请帮助我, 感谢
找到''字符的索引,并使用'SUBSTR? ()'从这一点删除所有内容。有点像'$ newstring = substr($ string,0,strpos($ string,'?'));' – Cyclonecode 2015-02-06 02:27:21
我的网址是:example.com/upload/produse/epilatoare/SE810%20Face.jpg?maxwidth=800&maxheight= 800 – 2015-02-06 03:52:32
但我想要清楚的地址:example.com/upload/product/epilatoare/SE810%20Face.jpg – 2015-02-06 03:52:51