开发者

Extract ID from URL

开发者 https://www.devze.com 2023-04-02 20:08 出处:网络
This is the link to writte the link in htaccess: RewriteRule ^carti-Dragoste/([a-zA-Z0-9_$\\-]+)\\.html$ book.php

This is the link to writte the link in htaccess:

 RewriteRule ^carti-Dragoste/([a-zA-Z0-9_$\-]+)\.html$ book.php        

This is the code to read the ID from link:

 $id_tot=explode("_",$_SERVER['REQUEST_URI']);    
$id=$id_tot['1'];    
$id1=substr($id,0,strlen($id)-5);

And this is the query:

 $query="SELECT * FROM carte WHERE id=" . $id1;    
 $res=mysql_query($query) or die(mysql_error());    
 while ($row=mysql_fetch_array($res))    
 {    
 $titlu=$row['titlu'];    
 $categorie=$row['categorie'];    
 $link=$row['link'];    
 $link2=$row['link2'];    
 $hits=$row['hits'];    
 $uploader=$row['uploader'];    
 $data_ad=$row['data_ad'];    
 $tags=$row['tags'];    
 $linkpoza=$row['linkpoza'];    
 $descriere=$row['descriere'];    
 $hits++;    
 }    
 $q="UPDATE carte SET hits='" . $hits . "' WHERE id='" . $id1 . 开发者_开发知识库"'";    
 mysql_query($q);

The link written is like this

    http://example.com/carti-Dragoste/ $titlu_$id.html     

The spaces from titlu are replaced with -

I need to read only the id from the url...

Thanks


I think this might work: $tetsUrl = "http://example.com/carti-Dragoste/ $titlu_$id.html"; $idOnlyTmp = array_pop(array_reverse(explode(".", $testUrl)); $idOnly = array_pop(explode("_", $idOnlyTmp)); echo $idOnly;

0

精彩评论

暂无评论...
验证码 换一张
取 消